When creating a virtual layer in QGIS, we can use the layer name of any existing layer in a query, like
SELECT layer1.*, layer2.*
FROM layer1
JOIN layer2 ON layer1.id = layer2.id
However layer names aren't necessarily unique. The docs say The query can use the name (or id) of existing vector layers
. I assumed this would be the Identifier
we can set in a layer's metadata options, but using these in a query results in a Referenced table layer_identifier in query not found!
message. (Nor is it possible to use the identifier in the Source definition of an embedded layer: Query execution error on DROP TABLE IF EXISTS "table1"; CREATE VIRTUAL TABLE "table1" USING gsVLayer('spatialite','layer_identifier',UTF-8): 1 - Provider error
).
We could use embedded layers, but then my problem is that we cannot use relative paths, as far as I can see (the project should be usable on different computers and OSes).
Is there a more robust mechanism than using layer names for creating a virtual layer?