Copy JSON column in Redshift -
i have import csv file in redshift s3. 1 of columns in table json format.
while using copy command, following error -
invalid timestamp format or value [yyyy-mm-dd hh24:mi:ss]    the command used -
copy api_log 's3://x/y' credentials 'aws_access_key_id=;aws_secret_access_key=' delimiter ',' maxerror 250 truncatecolumns; commit;
sample data -
c1 c2    c3    x       y     {a:b,c:d} 
if add quotes json , removequotes copy works.
put test file in s3:
echo x,y,'"{a:b,c:d}"' | aws s3 cp - s3://[bucket]/json/test_file.csv create table:
create table if not exists api_log (c1 varchar, c2 varchar, json_colum varchar(65535)); load:
copy api_log  's3://[bucket]/json/'  credentials 'aws_access_key_id=;aws_secret_access_key=' delimiter ','  maxerror 250  truncatecolumns removequotes; or, if don't quotes, can use tabs or other character not in data. e.g.:
echo -e "x\ty\t{a:b,c:d}" | aws s3 cp - s3://[bucket]/json/test_file.csv then:
copy api_log  's3://[bucket]/json/'  credentials 'aws_access_key_id=;aws_secret_access_key=' delimiter '\t'  maxerror 250  truncatecolumns removequotes; either way, get:
select * api_log;  c1 | c2 | json_colum  ----+----+------------  x  | y  | {a:b,c:d} 
Comments
Post a Comment