Preql icon indicating copy to clipboard operation
Preql copied to clipboard

Documentation for "..." in projection

Open manor opened this issue 3 years ago • 1 comments

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

manor avatar Apr 05 '21 00:04 manor

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.

erezsh avatar Apr 05 '21 01:04 erezsh