fix(engine/sqlite): added json_tree and json_each definitions#2570
fix(engine/sqlite): added json_tree and json_each definitions#2570orisano wants to merge 4 commits intosqlc-dev:mainfrom
Conversation
|
@kyleconroy I would like to introduce the concept of hidden table for tables like json_tree and sqlite_schema, which are included in the catalog but for which I do not want to generate code. |
|
I gave this a try locally, as the underlying bug is blocking us. Unfortunately, it still doesn't work for me on this sqlite query: -- name: LookUpVendors :many
SELECT
"vendor".*
FROM
vendor AS "vendor",
json_each("vendor".benefits) AS "benefit",
json_each("vendor".states) AS "state"
WHERE
"state".value IN (@state, "National Coverage")
AND "benefit".value = @benefit;Schema (extract): CREATE TABLE vendor(
id text PRIMARY KEY,
name text NOT NULL,
benefits text NOT NULL,
states text NOT NULL
);Error message: When I try the query in sqlite3 directly, it works. Thanks so much for working on this! |
|
Also, FYI, this rewrite works in v1.19 but fails with this PR: -- name: LookUpVendors :many
SELECT
vendor.*
FROM
vendor,
json_each(vendor.benefits) AS b,
json_each(vendor.states) AS s
WHERE
CAST(s.value AS text) IN (@state, "US")
AND CAST(b.value AS text) = @benefit; |
|
...although that query in v1.19 generates a miscompile, with a method signature like: func (q *Queries) LookUpVendors(ctx context.Context, benefit interface{}) ([]*Vendor, error) {(note that it only takes a single benefit argument, not a benefit and a state arg.) |
|
@josharian thanks! workaround: -- name: LookUpVendors :many
SELECT
vendor.*
FROM
vendor,
json_each(vendor.benefits) AS benefit,
json_each(vendor.states) AS state
WHERE
state.value IN (CAST(@state AS TEXT), 'National Coverage')
AND benefit.value = CAST(@benefit AS TEXT);
You can avoid the problem by doing these two things. |
|
This has resolved the query noted here 👏 |
|
Is there anything outstanding on this PR aside from conflicts? |
fix #1830