2

I have some rasters in PostGIS and I want to open just those which match to where clause. How can I do that? I have tried:

ds = gdal.Open("PG:host=<host> dbname=<dbname> table=<tablename> user=<user> password=<psswd> where='observ_date=\'2015-06-26\'::date'")

and some other combinations of quotes, but with no success. Everytime I got an error like this

ERROR 1: Error browsing database for PostGIS Raster properties : ERROR:  cannot cast type integer to date
LINE 1: ...r.alaska_mod13q1_ndvi where observ_date=2015-06-26::date gro...

It means that wrote quotes wrong. So how should I write quotes in where clause in PG connection string correctly?

  • 1
    Try using double quotes. Like this: ''. See this post. – Fezter Sep 15 '17 at 3:44
  • @Fezter thank you, but the same error. No quotes in a final string in PostgreSQL. – CzendaZdenda Sep 15 '17 at 3:49
  • @Fezter thanks a lot! '' does not help, but dollar-quoted string does :) So for example now I can use it like this: ds = gdal.Open("PG:host=<host> dbname=<dbname> table=<tablename> user=<user> password=<psswd> where='observ_date=$$'2015-06-26'$$::date'") and it seems to work :) – CzendaZdenda Sep 15 '17 at 4:00
3

As per this post, try using dollar-quoted strings.

So your code would look like this:

ds = gdal.Open("PG:host=<host> dbname=<dbname> table=<tablename> user=<user> password=<psswd> where='observ_date=$$'2015-06-26'$$::date'")

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.