M
M
Millerish2018-11-28 11:32:31
PostgreSQL
Millerish, 2018-11-28 11:32:31

PostgreSQL: How to add data?

I have columns: col1 text, col2 text, col3 double precision, col4 double precision, col5 numeric. Need to write data: text, "text2", "439, 86 [404]", "0.39", "0.11", "37.70%".
The code:

test=# COPY dataToImport2 FROM '/opt/DataToImport2.csv' WITH (FORMAT csv);

Mistake:
ERROR:  invalid input syntax for type double precision: "0,39"
CONTEXT:  COPY datatoimport2, line 1, column summaprodazhtyisrub: "0,39"

I understand that the error is related to the characters "," and "%". If you replace them, then there is no error. Can I write a request so that the replacement occurs automatically?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2018-11-28
@Millerish

First, copy to another table with text fields (temporary table is quite a suitable place), then insert .. select with a request to transfer where necessary with any manipulations along the way.
Or make a storage in any language and read the file through it, converting the data along the way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question