You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One annoyance in SQL is that it's quite difficult to create some data in code. This is generally used for sample tables when demonstrating something, or for quick lookup tables.
IME it ends up being something like:
select tim as first_name, smith as last_name, 30as age
union allselect mary, jones, 31union all
...
I think we could make this much nicer. The simplest approach would be to just do from_json (or _csv or _yaml), parse the inline string, and then convert to the verbose SQL representation. As above, it's not for loading lots of data; it's just for small samples.
With the more literal style, how would be represent multiple rows succinctly? It would be convenient to have a format that people can copy from somewhere else too, as opposed to a PRQL-specific format.
I had started making something like:
from csv:r#"
first_name, last_name, age
tim, smith, 30
mary, jones 31
"#
I had started with CSV since it doesn't need quotes (it wouldn't need the r#""# at first), and is more concise than JSON.
WDYT? Do you still prefer the more "PRQL-native" approach?
Hmmm, why not both? PRQL has nice highlighting, CSV is copy-pastable. There are use cases for both.
Problem with CSV is that there is no standard. comma/semicolon/tab/space, header/no header, spaces after comma are all ambiguous in different software.
Before adding r#""# think twice about how will be include regex literals. Also, in your example string literal starts with new line...
Before adding r#""# think twice about how will be include regex literals. Also, in your example string literal starts with new line...
I was thinking that r"\w" would be raw text, and the rust approach of r#"foo"# was a good way of extending this to multiple lines! WDYT?
Hmmm, why not both? PRQL has nice highlighting, CSV is copy-pastable. There are use cases for both.
Definitely agree. I do think there can be a temptation to build too many ways of doing something — it's difficult to turn ideas down! But for new users it can be confusing. Generally I would vote to do one thing and then assess if we need another.
Possibly in this case there is a real use for both though.
I do appreciate you keep things clean @max-sixty , I agree with your sentiment of only building one way to do things in the beginning. More ways will come as the language grows but in the beginning if we can keep it light I think it will go far.
That said , I still like the prql approach of from data , but it looks like it would only allow for one row. How many rows do you need in this approach ?
Something I've noticed that I miss from SQL as I'm writing documentation is the ability to start without a table; e.g. if we want to demonstrate an s-string, we need to have something like:
from employees
derive db_version: s"version()"
...whereas in SQL, that's just SELECT version(); no need for the from.
Hopefully as part of this we can make that easier; e.g.
Yes, this is very reasonable. it's a shame that this doesn't extend to inline sample data; and requires table modifications — particularly for analytical DBs where table modifications are expensive & rare.
Maybe the formats should be defined in modules instead of the core?
Maybe it should be possible to augment this with new data kinds from third-party modules?
Maybe someone want to from_tsv, from_ xml, from_bson, from_jsonb, from_excel, or from_rdf?
If you have from_string format:csv "..." then where format is specified as parameter (format:{format_type}) then would that format be possible to argument with new formats defined in modules that gets imported?
@vanillajonathan This has actually been implemented and the following works in the playground:
from_text format:json '[{"a":1,"b":2}]'
I believe the following should work too but for some reason I keep having problems with it. Can anyone reproduce the buggy playground behaviour for the example below?
I see. Maybe it should be possible to extend the formats used by from_text by importing formats from modules?
I find it rather confusing that from_text has no parenthesis, it makes me not know if its a language construct or if it is a function call. It seems from_text is defined in the std.prql file so it seems it is a function.
This could probably be documented or explained better. If you have a suggestion for something that's missing from the docs or that could be explained better, please feel free to submit a PR - this makes a great first PR!
Activity
aljazerzen commentedon Apr 2, 2022
I would rather propose we use
fromfor this:From can then be thought as "data source" either as a table, inline data or csv/json/yml
Also there has to be quotes on strings.
max-sixty commentedon Apr 2, 2022
Great, agree with the
from(/table?) syntax.With the more literal style, how would be represent multiple rows succinctly? It would be convenient to have a format that people can copy from somewhere else too, as opposed to a PRQL-specific format.
I had started making something like:
I had started with CSV since it doesn't need quotes (it wouldn't need the
r#""#at first), and is more concise than JSON.WDYT? Do you still prefer the more "PRQL-native" approach?
aljazerzen commentedon Apr 2, 2022
Hmmm, why not both? PRQL has nice highlighting, CSV is copy-pastable. There are use cases for both.
Problem with CSV is that there is no standard. comma/semicolon/tab/space, header/no header, spaces after comma are all ambiguous in different software.
Before adding r#""# think twice about how will be include regex literals. Also, in your example string literal starts with new line...
Ah, so much problems with such a simple feature.
max-sixty commentedon Apr 2, 2022
I was thinking that
r"\w"would be raw text, and the rust approach ofr#"foo"#was a good way of extending this to multiple lines! WDYT?Definitely agree. I do think there can be a temptation to build too many ways of doing something — it's difficult to turn ideas down! But for new users it can be confusing. Generally I would vote to do one thing and then assess if we need another.
Possibly in this case there is a real use for both though.
qorrect commentedon Apr 3, 2022
I do appreciate you keep things clean @max-sixty , I agree with your sentiment of only building one way to do things in the beginning. More ways will come as the language grows but in the beginning if we can keep it light I think it will go far.
That said , I still like the prql approach of
from data, but it looks like it would only allow for one row. How many rows do you need in this approach ?max-sixty commentedon Apr 3, 2022
Generally for sample data I've needed 5-10...
aljazerzen commentedon Apr 4, 2022
Ah, in this case we would need nested arrays:
but now, CSV looks better because it has headers at the top.
max-sixty commentedon Apr 10, 2022
Something I've noticed that I miss from SQL as I'm writing documentation is the ability to start without a table; e.g. if we want to demonstrate an
s-string, we need to have something like:...whereas in SQL, that's just
SELECT version(); no need for thefrom.Hopefully as part of this we can make that easier; e.g.
...might be sufficient
max-sixty commentedon Apr 10, 2022
CSV is not a great format, but it does have this one advantage! Are there nicer formats that also can have column names specified only once?
aljazerzen commentedon Apr 11, 2022
SQL has that:
Pandas has
columnsparamater ofDataFrameconstructor. In prql this would look like:aljazerzen commentedon Apr 11, 2022
Also, currently this is a valid query:
max-sixty commentedon Apr 11, 2022
Ah, I didn't even realize that! That's great!
Yes, this is very reasonable. it's a shame that this doesn't extend to inline sample data; and requires table modifications — particularly for analytical DBs where table modifications are expensive & rare.
max-sixty commentedon Apr 15, 2022
Postgres has something decent for this: https://www.postgresql.org/docs/current/queries-values.html
26 remaining items
fix: Renames from_csv to from_text (#286) (#1514)
vanillajonathan commentedon Feb 10, 2023
Maybe the formats should be defined in modules instead of the core?
Maybe it should be possible to augment this with new data kinds from third-party modules?
Maybe someone want to
from_tsv,from_ xml,from_bson,from_jsonb,from_excel, orfrom_rdf?If you have
from_string format:csv "..."then where format is specified as parameter (format:{format_type}) then would that format be possible to argument with new formats defined in modules that gets imported?snth commentedon Feb 10, 2023
@vanillajonathan This has actually been implemented and the following works in the playground:
I believe the following should work too but for some reason I keep having problems with it. Can anyone reproduce the buggy playground behaviour for the example below?
vanillajonathan commentedon Feb 10, 2023
I see. Maybe it should be possible to extend the formats used by
from_textby importing formats from modules?I find it rather confusing that
from_texthas no parenthesis, it makes me not know if its a language construct or if it is a function call. It seemsfrom_textis defined in thestd.prqlfile so it seems it is a function.snth commentedon Feb 10, 2023
"Language constructs" are pretty much all functions (it's functions all the way down). Function calls don't take parentheses in PRQL and PRQL is more like functional languages like Haskell in that respect. There's some more detail here: https://prql-lang.org/book_integrated/
This could probably be documented or explained better. If you have a suggestion for something that's missing from the docs or that could be explained better, please feel free to submit a PR - this makes a great first PR!
vanillajonathan commentedon Feb 10, 2023
The link just points to the book not a particular page on the book.
So I guess
from,filter, andtakeare just functions too?docs(web): Use external book link
max-sixty commentedon Feb 11, 2023
(closing as completed, feel free to continue the discussion re functions!)
docs(web): Use external book link (#1780)
docs(web): Use external book link (PRQL#1780)
docs(web): Use external book link (#1780) (#1781)