How to define the types of columns when doing a copy for PostgreSQL

2

I'm trying to make a copy for a table I have in Postgre, however it's giving the following error:

  

ERROR: invalid input syntax for type timestamp: "data_cadastro"

I wanted to know how to define this field as timestamp .

Follow the code:

COPY tb_reclamacao(ordem, processo, data_cadastro, data_resposta, data_programacao, id_base, id_usuario, id_tipo_reclamacao, id_situacao) 
FROM 'C:\ANEXOS\tb_reclamacao.txt'  
using delimiters ';'
    
asked by anonymous 20.04.2015 / 19:29

1 answer

1

The date format is not the same as the database.

By default, the format is YYYY-MM-DD HH: MM: SS

You can change the date format of the section with the command:

SET datestyle TO (format);

follows list of formats below:

  • MDY | month-day-year | 12/16/2011
  • DMY | day-month-year | 12/16/2011
  • YMD | year-month-day | 2011-12-16
  • ISO | ISO 8601 / SQL standard (default) | 2011-12-16 07: 37: 16-08
  • POSTGRES | verbose style | Fri Dec 16 07:37:16 2012 PST
  • SQL | traditional style | 12/16/2011 07:37:16 PST
  • GERMAN | regional style | 16.12.2011 07:37:16 PST

To use the SQL option, you must enter the month and day order. Ex:

  • SQL, DMY | day / month / year | 12/17/2007 3:37:16 PM CET
  • SQL, MDY | month / day / year | 12/17/2007 07:37:16 PST

To insert data with the date in Brazilian format, simply run the select below before performing COPY:

// This will change the format of the date only for this session. SET datestyle TO (SQL, MDY);

    
17.11.2015 / 18:43