0

I'm using copy to import a csv file into postgres, one of the fields contains a time value in HH:MM:SS formate. I want to be able to set this to a TIMESTAMP field, I've looked through lots of documents but I'm struggling to work out what field type to set it to. I see lots of reference to creating fields with timezones or not, a date etc, not really what I'm after. The ultimate aim is to create reports based on time intervals, e.g. all data between 00:00:00 and 06:30:00 etc

2 Answers 2

5

A timestamp in postgres is date and a time combined. For times only use the type time or time with time zone.

Sign up to request clarification or add additional context in comments.

Comments

0

Here is an example:

CREATE TABLE table01
(
  rowid bigint NOT NULL,
  time_field time without time zone,
  CONSTRAINT table01_pkey PRIMARY KEY (rowid)
)
WITH (
  OIDS=FALSE
);

And here is an file example:

100,12:30:59
200,08:59:01

You can importe this last file to table01 using copy command like this:

COPY table01 from 'c:/tmp/table01.txt' with csv

Considerning that the file named table01.txt located at : c:/tmp/ folder.

Reference: copy

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.