Importing a txt file in PostgreSQL 9.6

4

Personal 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 to postgres 9.6, but when I use the

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

It only imports the data if the id field is like varchar. 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 happening? I also tried changing the column from the varchar table to integer with the following command

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

The same error mentioned above occurred.

    
asked by anonymous 04.01.2017 / 13:28

1 answer

2

To be able to work around this situation, you can create a procedure, create a temporary table, and import this file into the temporary table. Then do insert with select from temporary table to official table.

This way you will be able to manipulate the data.

    
04.01.2017 / 16:42