.load ./pivot_vtab
.headers on
.mode column
CREATE TABLE t1 AS
WITH t(r, c, v) AS (
SELECT *
FROM (
VALUES
('a a', 'x x', 1),
('c c', 'y y', 2),
('b b', 'x x', 3),
('a a', 'y y', 4),
('c c', 'z z', 5)
)
)
SELECT * FROM t;
CREATE VIRTUAL TABLE pivot USING pivot_vtab(
(SELECT r FROM t1 GROUP BY r),
(SELECT c, c FROM t1 GROUP BY c),
(SELECT v FROM t1 WHERE r = ?1 AND c = ?2)
);
SELECT * FROM pivot;
Output of docker build -t pivot_vtab/issue . is as expected:
r x x y y z z
---------- ---------- ---------- ----------
a a 1 4
b b 3
c c 2 5
(SELECT id c_id, name FROM c), -- Pivot table column definition query
This may indicate that the extension only expects a sort of star schema, but it would exclude many cases were pivot table is desired. I've answer a couple of SQLite pivot question to estimate that (one, two).
Steps to reproduce
Dockerfile
script.sql
Output of
docker build -t pivot_vtab/issue .
is as expected:If I change
t1
in the script like this:It fails with:
Expected behaviour
If the input data (provided by the 3 queries) doesn't fit the requirement, there's an error message that explains it.
Actual behaviour
There's non-informative "vtable constructor failed" error message.
Additional information
The behaviour is the same with
BINARY
collation. Though the comparison is false by default anyway.This may indicate that the extension only expects a sort of star schema, but it would exclude many cases were pivot table is desired. I've answer a couple of SQLite pivot question to estimate that (one, two).