Import txt file into Postgresql 9.6

Asked

Viewed 247 times

4

Guys, I have the following problem: I have a file in txt format with the following information:

1;Helder;Masculino;GO
2;João;Masculino;RJ
3;Maria;Feminino;PR
4;Pedro;Masculino;MA

I used this example to test the import for postgres 9.6, but when I use the command

COPY clientes FROM 'C:/clientes.txt' USING DELIMITERS ';'

it only matters the data if the id field is varchared. When I create a table with the id field as integer it always gives the message

invalid input syntax for integer

Can anyone tell me what might be going on? I also tried to change the column of the varchar table to integer with the following command

ALTER TABLE clientes ALTER COLUMN id TYPE integer USING id::INTEGER

the same error cited above occurred.

  • In some row the first field on the left comes blank?

  • No, all lines have only integer numbers

1 answer

2

In order to get around this situation what you can do is create a precedent, in this process create a temporary table, and import this file into the temporary table, done this, make Insert with select from the temporary table to official table.

That way you can manipulate the data.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.