0

I have some data stored in a Postgres 13 Postgis 3.1 table that looks like

id(integer),valid_to(timestamp),language(varchar),name(varchar)

1,2021/08/16 11:19:06.493,eng,London

2,2021/08/16 11:19:06.493,cym,Cardiff

3,NULL,,London

As you can see row 3 contains a NULL value for the timestamp and an empty value for the language attributes.

When I use the following GDAL command to export this to CSV the exported data gets corrupted if I use the -lco STRING_QUOTING=ALWAYS.

ogr2ogr -f CSV Output.csv PG:"connection string" -lco STRING_QUOTING=ALWAYS -lco GEOMETRY=AS_WKT

How can I keep the values (NULL and empty string)?

3
  • Did you try to use -sql "SELECT id,CASE valid_to IS NULL THEN 'NULL' else valid_to END AS valid_to, language,name FROM mytable" to be sure NULL becomes a NULL string instead of throwing an error?
    – ThomasG77
    Aug 16 at 11:45
  • @ThomasG77 - thank you. Yes I could. It means a lot of writing SQL for my ogr commands so was hoping there was a GDAL switch. So I think I will do it in PostGIS and have a simpler export command. Thanks for your help tho
    – tjmgis
    Aug 16 at 15:37
  • 1
    Maybe someone have clues I do not have, maybe. Let's wait for other answers/comments if any
    – ThomasG77
    Aug 16 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.