0

I want to import the data of the following format (in a csv file) into postgres:

   ('string1', 'string2', 'string3', 1999-10-10,2000-10-10)

Here column1, column2, column3 are of type string and column4, column5 are of type date. My problem is, apart from normal dates like '1999-10-10'. I also want dates in "BC" to be imported into postgres, but I am not getting how to achieve the same. Can someone please help me with this?

Eg. I want dates of the following format to be imported into postgres:

  ('string1', 'string2', 'string3', 199-10-10 BC, 200-10-10 BC)

Is it possible to important csv fies with dates in BC as well as AD into postgres. If yes, can someone please help me with this as I am a complete novice at postgres?

1 Answer 1

2

From PostgreSQL docs:

Valid input for the time stamp types consists of the concatenation of a date and a time, followed by an optional time zone, followed by an optional AD or BC.

Date and time input is accepted in almost any reasonable format, including ISO 8601, SQL-compatible, traditional POSTGRES, and others.

And, most important in your case:

Remember that any date or time literal input needs to be enclosed in single quotes, like text strings.

So you need to quote datetime strings in the CSV, e.g. '199-10-10 BC'.

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

2 Comments

So is ('string1', 'string2', 'string3', '199-10-10 BC', '200-10-10 BC') a correct input format can I import it directly into postgres
@JannatArora: exactly.

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.