Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create an action that select many rows from PostGIS table to show many lines in QGIS. How can i select many rows from table with python to add these rows in a layer?

Thank you

share|improve this question
what do you mean registers? – Nathan W Apr 22 '13 at 11:36
registers = rows – user1573901 Apr 22 '13 at 13:45
do you just want to add a postgis layer using python? can you add more clarity? – vinayan May 23 '13 at 2:51

assigning an Action Type of Python you can add multiple column field values (separated with a space), as follows:

u'[% "col_name1" %]' + " " + u'[% "col_name2" %]' 

if you need to add data from numerous rows and create a new table view in QGIS, you should think about creating a plugin

share|improve this answer
Can I make a action python with that query?:SELECT * FROM pathways WHERE gid IN(SELECT mpp_path_id FROM meetingpoints_paths WHERE mpp_meeting_id = [% "gid" %]) – user1573901 Apr 22 '13 at 14:15
It looks like you are using PostGIS based on the "gid" primary key. However, if you were using sqlite/spatialite you could perform SQL using: import sqlite3; con = sqlite3.connect("mydatabase.sqlite"); cur = con.cursor(); cur.execute("SELECT...the rest of my SQL statement ") – user12711 Apr 22 '13 at 14:43
the python sqlite3 module will not handle spatialite geometries. alternately, would want to import the pyspatialite module. and use pyspatialite.dbapi2.connect("mySpatialite_DB.sqlite") to establish an object for your cursor to perform SQL on – user12711 Apr 22 '13 at 15:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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