Skip to content
Advertisement

I am unable to upload a .csv file in postgresql database because I don’t know how to put date structure in sql query

I downloaded a csv file for practising where date format is of two types as shown in picture. the picture is here I tried to change the format to yyyy-mm-dd in excel but it is not happening. and also, I can’t upload the file in database in my postgresql. I used the data type “date” but it says I need a different datestyle.

code I have used:

any guidance will be helpful, thanks

Advertisement

Answer

To summarize comments into sort of an answer:

CSV values are text, so your date needs only to be in a correctly formatted date style. The second copy failed because the date style date order was ‘dmy’ and the value is 7/14/2021 and 14 is not a month number. This is why there is a date/month order setting, as 7/11/2021 could either be ‘July 11 2021’ or ‘November 7 2021’. Postgres needs the user to tell it what ordering it is looking at.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement