Created
July 3, 2019 09:59
-
-
Save laroo/53b528665993116db44fd4487e88fa00 to your computer and use it in GitHub Desktop.
Quick CSV to table/CTE in PostgreSQL (RDS Aurora)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH csv_data AS ( | |
SELECT string_to_array(regexp_split_to_table( | |
'2019-07-01,6001,49 | |
2019-07-02,6001,91 | |
2019-07-03,6001,23 | |
2019-07-04,6001,79 | |
2019-07-05,6001,16 | |
2019-07-06,6001, | |
2019-07-07,6001, | |
2019-07-08,6001,54 | |
2019-07-09,6001,48 | |
2019-07-10,6001,36 | |
2019-07-11,6001,06 | |
2019-07-12,6001,34', '\n'), ',') as csv_row | |
) | |
SELECT | |
csv_row[1]::date AS order_date, | |
csv_row[2]::int AS item_id, | |
NULLIF(csv_row[3], '')::int AS units | |
FROM | |
csv_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quick CSV to table/CTE in AWS Redshift: