1

I am experiencing difficulties with SQL syntax in a Virtual Layer. I can do the simplest query form such as:

SELECT *
FROM mytable

and this displays on my canvas.

However, if I try to name fields in my table such as:

SELECT field1, field2
FROM mytable

this doesn't create an error but does not display on my canvas.

Can anyone offer suggestions, please? I have tried it on several layers.

2
  • Are you getting something like? gis.stackexchange.com/questions/328990/…
    – GeorgeC
    Commented Jul 17, 2019 at 4:47
  • 2
    If none of field1 or field2 is a geometry fields nothings will appear on the map canvas ... is that what u mean ? What kind of query do u intend to do ?
    – Snaileater
    Commented Jul 17, 2019 at 5:01

1 Answer 1

5

For virtual layers, the actual geometry of the features are in a column named geometry.

In your first query when you select all columns, you are implicitly selecting the geometry column. That's why you can see the features on the canvas.

In the second query, you are only selecting non-spatial columns (field1, field2 etc.) and they show up as a table. To fix that, update your query like below

SELECT field1, field2, geometry
FROM mytable
1
  • Thank you for your help. I hadn't realised that a geometry field is required in the syntax. This solves my problem. Well done. Commented Jul 17, 2019 at 11:15

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.