I’m trying to import a tabel from a CSV file. The table has two columns whose values are "$##,##". When I try to import I get an error. the error
I’ve already tried using Numeric, Double Precision and Money my column data types as the data type to no avail. What am I doing wrong? Thanks 😉
2
Answers
You should use
numeric(15,2)
.And yes, you won’t be able to load the data using
COPY
. One way to deal with that is to useCOPY
to load the data into a temporary table, where the column has data typetext
. In a second step, you can use something likeSet
lc_numeric
to a German locale to have PostgreSQL recognize the comma as a decimal point.I’m sure there are workarounds within PostgreSQL itself, but when I’m faced with this issue I tend to take the simplest route: I import the CSV file into Excel, reformat the columns to remove commas, and then save back to CSV.
Not always possible, I know, but it is simple. You just have to be careful when bringing CSVs into Excel that you import the data rather than just clicking on the file to open it. Excel will reformat numbers that should be stored as text (such as U.S. Zip codes that begin with a zero).