erezsh / Preql

An interpreted relational query language that compiles to SQL.
Other
616 stars 13 forks source link

Documentation for "..." in projection #22

Open manor opened 3 years ago

manor commented 3 years ago

I get why this:

join(c: Country.name, n:["Palau", "Nauru"].item) {...c}

returns this:

image

and even why this:

join(c: Country.name, n:["Palau", "Nauru"].item) {...n}

returns this:

image

but what does this even mean?

join(c: Country.name, n:["Palau", "Nauru"].item) {...}

because this is what it returns:

image

In the context of a project, '...' means all the columns, but the type of the result of the join and/or the meaning of "..." are a bit unclear. Also, I understand rows and tables but it looks like entire structs are being returned in the last case:

image

erezsh commented 3 years ago

Yes, the join() operation returns a struct for each table. Joining two tables creates two structs.

From the docs (https://preql.readthedocs.io/en/latest/preql-modules.html#join):

Returns: A new table, where each column is a struct representing one of the joined tables.

When you do join_result{...n}, you are telling Preql to inline the struct called n. You could also do join_result{n.item}, with a similar result in that case.

In Preql, my_table {...} is essentially a no-op, which just returns all the columns. If they are structs, they will remain structs.

I hope it's clearer now.

If you have suggestions on how to improve the docs or tutorial, I'll be happy to hear them.

edit: You can also do join_result{...n, ...c}, which will inline both structs.