[Qgis-user] Problem with adding a PostGIS query using Python

Giuseppe Sucameli brush.tyler at gmail.com
Thu Jun 28 01:08:53 PDT 2012


Hi,

there's already a open ticket about that problem, see [1].

Regards.

[1] http://hub.qgis.org/issues/5883

--
Giuseppe Sucameli

On Jun 27, 2012, at 6:33 PM, "James Stott" <James.Stott at npaconsult.co.uk> wrote:

> I cannot seem to get this query to work. The python code I am using is:
>
>           db_conn = "dbname=database' host=SERVER port=5432
> user='postgres' password='xxxx'"
>           id_field = "gid"
>           table="(SELECT * FROM \"designations\".\"table\" WHERE
> ST_DWithin(ST_GeomFromText('POINT(451583 129144)',27700),
> \"table\".\"geom\", 2000))"
>           uri = "%s key=%s table=%s (geom) sql=" %
> (db_conn,id_field,table,)
>           layer = QgsVectorLayer(uri, "testlayer", "postgres")
>           QgsMapLayerRegistry.instance().addMapLayer(layer)
>
> QGIS keeps telling me the following:
>
> Unable to access the "(""SELECT" relation. The error message from the
> database was: ERROR: relation "("SELECT" does not exist LINE 1: SELECT *
> FROM "(""SELECT" LIMIT 1
>
> It's almost as if something is automatically putting another SELECT
> statement in front of my SELECT statement.
>
> I can get this query to load using the DB manager plugin SQL window.
>
> I have read this article and it still errors.
>
> http://www.carsonfarmer.com/?p=713
>
> Does anyone know why this doesn't work?
>
> Using QGIS 1.8 on Windows 7 64bit, data is in a PostGIS 2.0 database.
>
> James Stott BSc (Hons) MSc | Senior Professional
> Nicholas Pearson Associates | 30 Brock Street | Bath | BA1 2LN
> T: 01225 445548 | M: -
> http://www.npaconsult.co.uk/
>
> http://www.npaconsult.co.uk/http://www.npaconsult.co.uk/about-news.asp
>
> http://www.npaconsult.co.uk/terms.asp
> This Electronic Transmission is intended only for the attention of the addressee. It may contain privileged and confidential information. If you are not the person for whom it is intended, you must not copy, distribute or take any action in reliance on it. If you have received this electronic transmission in error please notify us immediately by telephone, delete the transmission and destroy any hard copies.
> Nicholas Pearson Associates has used all reasonable efforts to ensure that this message and any attachments are free from viruses.
> Nicholas Pearson Associates, 30 Brock Street, Bath, BA1 2LN , Tel: +44 (0) 01225 445548, Fax: +44 (0) 01225 312387, Website: http://www.npaconsult.co.uk/
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user



More information about the Qgis-user mailing list