I have a file that I want to copy into a table, the table has three columns,
create table item (
name Text,
t Time without time zone,
status Text);
the File looks like this:
book, 2022-08-13 13:30:01,out
char,2022-08-13 13:35:22, inside
lather,2022-08-13 13:36:00, out
is there a way to convert the Datetime value to time value without do a table with Datetime and then Altering it?
1
The CSV file:
cat time_test.csv
book, 2022-08-13 13:30:01,out
char,2022-08-13 13:35:22, inside
lather,2022-08-13 13:36:00, out
Create the table:
create table item (
name Text,
t Time without time zone,
status Text);
Import the data using psql
:
copy item from time_test.csv with csv
COPY 3
The result:
name | t | status
--------+----------+----------
book | 13:30:01 | out
char | 13:35:22 | inside
lather | 13:36:00 | out
The datetime string will automatically be cast to time on import.
6