I have run a code in pgAdmin it returns 43 rows of data. I took the same code ran it in QGIS and found the same row of data. However while trying to add the new data into the map QGIS comes with the error

WARNING Invalid PostgreSQL layer

I ran two forms of this code and both came back with the same error.

SELECT pin, ST_MakeValid(parcels.geom), ST_MakeValid(address_points.geom)
FROM   parcels
JOIN   address_points
       ON ST_Contains(parcels.geom,address_points.geom)
WHERE  class = 'CLUB';


FROM   parcels
JOIN   address_points
       ON ST_Contains(ST_MakeValid(parcels.geom), ST_MakeValid(address_points.geom))
WHERE  class = 'CLUB';

What I am trying to do is select all the parcel that contains club within, and will add the new data to a new table (create table AS ....). I was making the map first to see if the data was good to map, which lead to the above error.

  • The first query returns two geometries, and the second returns none. Neither one is a valid layer. ST_MakeValid has a tangible cost -- best practice is to run it once in an UPDATE; then you don't need to slow down every query.
    – Vince
    Commented Dec 13, 2020 at 1:45
  • So maybe select all info contain to parcels. select *
    – Schoollife
    Commented Dec 14, 2020 at 14:24
  • I have had this error more times. It may have to do with not having PK's in those tables. Commented Dec 14, 2020 at 21:06

1 Answer 1


Normally that error occurs when QGIS cannot find a column with a unique "primary key". Ensure that the pin column has no duplicates, or add another field with a proper primary key.

See this thread for using the row number

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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