On Fri, 11 Dec 2015 14:09:29 -0800 (PST), David Anderson wrote:
> This query does not return any rows
>
> select sqr.geometry,eg.geometry
> from square1 as sqr
> join
> ElementaryGeometries as eg
> on (eg.origin_rowid=sqr.rowid and eg.f_table_name='square1')
>
Hi David,
a Virtual Table is not a genuine table as any other; it really
is a driver pretending to simulate a table (that is not exactly
the same). And very ofter a Virtual Table can only support a
very limited set of predefined options in order to properly work.
select sqr.geometry,eg.geometry
from square1 as sqr
join
ElementaryGeometries as eg
on (eg.f_table_name='square1' and eg.origin_rowid=sqr.rowid);
if you write your query in the above form it will nicely work;
if you swap the positions of the f_table_name and origin_rowid
columns it will not work simply because the underlaying driver
will then be unable to correctly retrieve its invocation arguments
following its predefined order.
> [1]
>
> is not entirely clear about whether the rowid of the table is being
> used or if the primary key is being used.
>
accordingly to the general principles of the SQLite architecture,
if the Primary Key has just a single column declared of the
INTEGER type then ROWID will simply be an alias name for the
Primary Key column.
in any other case (a PK formed by a single column but not of the
INTEGER type, or a PK formed by several different columns, or no
PK at all) the ROWID will simply correspond to the physical position
of the row within the table.
the "origin_rowid" term always expects to match an INTEGER; so
as a general rule it's safe to use the ROWID.
in the special case of a table declaring a single-column PK
of the INTEGER type (which always is the best practice on
SQLite) you can indifferently use the name of the PK column
or ROWID as you wish better.
bye Sandro