feat: Support for sql arrays as s[...]#5312
Conversation
… sql_array_support
for more information, see https://pre-commit.ci
|
Hi, Thanks for the PR. []s were much more prominent before the switch to {} for the tuple syntax. You're right about the use for literals but maybe that should get the special syntax instead? I think it might be worth reconsidering. We'll have to think about what's more common in practice. I'm going to think about this a bit. |
|
Yes, we could make |
|
interesting suggestion! I'm trying to think whether there's some way of designing normal array syntax to work, without special-casing thanks for your excellent PR summary. do you happen to also have concrete examples of cases where the existing approach doesn't work? i.e. "can not be passed into functions to be interpolated into s-strings....Since PRQL doesn't support variadic functions, I couldn't add an array constructor as a pure s-string either." |
|
Hi Max! Thank you!
I also couldn't define something like
Are these the examples you were looking for? Also, once we have a way of constructing arrays, then map construction can be done simply with an s-string: #5303 On the previous proposal to merging my |
|
Hi guys! I think compiling existing Now this: compiles to: |
|
@max-sixty @snth what are your thoughts on the updated version? Meanwhile, I'm adding this to my org's fork to simplify people's life, but I'd prefer not to diverge from the upstream too much, so if you think this is a good addition to PRQL, I could look into adding tests/updating the docs, etc., to merge this. Thanks! |
|
Thanks @rvalek . Your examples look great! Could you please also check the other use of array literals in expression like: from [{a=1}, {a=2}] |
|
Thank you, @snth! I forgot to check this case. With my changes, So, looks like no change there. |
for more information, see https://pre-commit.ci
|
this is v reasonable, I like the newer version! could we understand why the tests are failing? that's a requirement for merging |
|
Of course. which, I think, is a good thing. |
|
@max-sixty @snth we are all green now -- updated a couple tests and added one. |
|
very nice! clever approach in the end, thanks for working through it) (I'm sorry I didn't hit the button sooner, always feel free to @ me after a couple days...) |
|
Really appreciate your guidance here and all your work on PRQL, @max-sixty & @snth! Also, would you like me to write a short note for this doc page to showcase the new functionality? |
Hi!
I have a use-case requiring SQL-level arrays (usually
[...]orARRAY[...]in SQL): #5303.I see that the current PRQL-level arrays written in square brackets are mainly used to represent the list literals in expressions like
x IN (1,2,3), and can not be passed into functions to be interpolated into s-strings.Since PRQL doesn't support variadic functions, I couldn't add an array constructor as a pure s-string either.
This PR introduces new syntax:
s[...]that compiles into SQL-level array literals, which can also be passed into s-strings to support my original use-case of constructing maps from arrays.Example usage:
Compiles to:
I understand that adding new syntax (and a new
SqlArraytype) is a big deal, so I don't expect this to be adopted as-is. I'd be happy to refine this to match the design direction that better suits your vision.I am also not very experienced with both Rust and PRQL, so any criticism is welcome.
Thanks!
Robert
UPD: proposal changed -- see #5312 (comment)