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 have problem with QGIS (2.0.1), PostGIS (2.0.4) combination. - A can load tables or views by Add PostGIS layer. This is OK. - But a can't load data by DB Manager and SQL Window. Executing query run but load result is problem.

Error message is:

PostgreSQL layer has no primary key

But Primary key exist in table. DB Manager find out them itself.

Do you have any idea where is problem?
Could my problem be with different schema then public?

Edit: Do this when I click to Load Now only. And realy do this outside public schema. In public schema it's OK.

share|improve this question
When does this message come up? Is it when you hit Execute or when you hit Load Now? – James S Nov 13 '13 at 10:08
up vote 2 down vote accepted

QGIS needs more than a primary key, that primary key field has to be an integer. What I do if I have a query or table that doesn't have a unique interger field I'll fake one in my query with the row_number window function.

SELECT row_number() OVER() As fake_id, geom FROM blahblahblah

Then in the Load as New Layer screen I click Retrieve columns, then set the primary key drop down to my new fake_id field.

For more information on window functions check out Postgres' manual:

share|improve this answer

Check your SQL query statement. The QGIS SQL Query block doesn't like a semicolon at the end of it. Simply get rid of the semicolon (;) if you have so in your query. Under load as new layer, specify your unique value and geometry column, and use Retrieve columns to test these two columns. If all is good, it should work.

Good luck,


share|improve this answer
Note that you don't need to sign your posts "in line" because your signature and link is automatically added. – BradHards Jan 17 '15 at 1:42

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.