Tuesday 15 September 2015

postgresql - Data correction exporting CSV file to Postgres -



postgresql - Data correction exporting CSV file to Postgres -

i importing csv file postgres, , know how import right info type while using copy command. instance, have column column_1 integer; , want insert value 6 csv file.

i run command copy "table" 'path/to/csv' delimiters ',' csv; , every time seek error error: invalid input syntax integer: "column_1". figured out it's because automatically importing every piece of info csv file string or text. if alter column type text works successfully, defeats purpose of using number need various calculations. there way conserve info type when transferring? there need alter in csv file? or there datatype assign column_1? hope makes sense. in advance!

i did , worked flawlessly: set plain number in stack.csv (the stack.csv has 1 value 6)

# create table stack(i int); # \copy stack 'stack.csv' (format csv);

i read in comment have 25 columns in csv file. need have @ to the lowest degree 25 columns in table. columns need mapped csv. if have more 25 columns in table need map columns mapped csv. that's why works @ text field because info set in 1 row cell.

if have more columns "fields" in csv file format this

\copy stack(column1, column2, ..., column25) 'stack.csv' (format csv);

postgresql csv sql-copy

No comments:

Post a Comment