Postgresql copy from CSV with dynamic date -


i have following command table in postgresql 9.3 database:

command ------------------------------------------------------------- id               | purchased_date                       | ... integer not null | timestamp without time zone not null | ... 

now want fill table data csv file. csv file contains example following values:

1,"2016-04-18 09:37:30" 2,"2016-04-17 09:37:30"  ... 

when \i 'my_csv_file.csv' works great. want have csv file dynamic dates in order not regenerate csv file when want reload database (this test purposes). have like:

1,"current_datetime - interval '1 day'" 2,"current_datetime - interval '2 day'" 

but when execute same command \i 'my_csv_file.csv' have error error: date/time value "current" no longer supported. possible want ?

you can use temporary table offsets, insert it.

csv:

1,"interval '1 day'" 2,"interval '2 day'" 

queries:

create temporary table tmp_table (   id int,   offset_ interval ); 

import csv table, then

insert main_table (id, purchased_date )     (select id, now()-offset_ tmp_table); 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -