Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emulating table-valued parameters with JSON #51

Closed
phrrngtn opened this issue Sep 12, 2022 · 1 comment
Closed

emulating table-valued parameters with JSON #51

phrrngtn opened this issue Sep 12, 2022 · 1 comment

Comments

@phrrngtn
Copy link
Contributor

This is a just an FYI about something I found cool and interesting. No action is required.

The define extension is a great addition to the list. Really awesome.

While doing some experimentation with lifting of functions between Excel and SQLite and vice versa, I see that it is easy to box a table-valued parameter as JSON and then unbox it in the 'sproc'.

sqlite> create virtual table [L.FUNNY] using define((WITH T(n) AS (SELECT E.value->>0 as n FROM JSON_EACH(:j) AS E) SELECT n FROM T));
sqlite> select * FROM [L.FUNNY]("[[1],[2],[3]]") as F;
1
2
3

sqlite> WITH A AS (
  SELECT json_group_array(json_array(s.value)) as arr 
  FROM generate_series(1,5) as s
) 
SELECT F.* FROM A, [L.FUNNY](A.arr) as F; 
n                                                                                                                                                 
1                                                                                                                                                 
2                                                                                                                                                 
3                                                                                                                                                 
4                                                                                                                                                 
5                                                                                                                                                 
@nalgeon
Copy link
Owner

nalgeon commented Sep 12, 2022

Nice trick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants