Skip to content

Commit

Permalink
selecting entire rows as documents
Browse files Browse the repository at this point in the history
  • Loading branch information
deobald committed Jan 12, 2024
1 parent 98c12a6 commit c2ffe4f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
14 changes: 13 additions & 1 deletion docs/print.html
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,8 @@ <h2 id="object"><a class="header" href="#object">OBJECT</a></h2>
<h2 id="dynamic-literals"><a class="header" href="#dynamic-literals">Dynamic Literals</a></h2>
<h3 id="row-literals"><a class="header" href="#row-literals">Row Literals</a></h3>
<p>It is possible return an entire document (row) as a single literal value.
The syntax is akin to Postgres <a href="https://www.postgresql.org/docs/current/rowtypes.html"><code>ROW</code> literals</a>.
The syntax is akin to Postgres
<a href="https://www.postgresql.org/docs/current/rowtypes.html"><code>ROW</code> literals</a>.
Unlike <code>table.*</code>, which pads non-existent columns with <code>NULL</code>,
a row literal returns exactly the schema specified for each individual row.</p>
<ul>
Expand All @@ -830,6 +831,17 @@ <h3 id="row-literals"><a class="header" href="#row-literals">Row Literals</a></h
<p>Example usage:</p>
<pre><code class="language-sql">SELECT { products.* } FROM products;
</code></pre>
<p>As a shorthand, a table's name may be used in the <code>SELECT</code> clause to return
entire rows as documents:</p>
<pre><code class="language-sql">-&gt; SELECT users FROM users;
-- [{'users': {'email': '[email protected]', 'name': 'Patrick'}},
-- {'users': {'email': '[email protected]', 'name': 'Preethi'}}]
</code></pre>
<p>NOTE: When a table contains a column of the same name, the column takes precedence
and a single column is returned, as usual:</p>
<pre><code class="language-sql">-&gt; SELECT status FROM status;
-- [{'status': 'error'}, {'status': 'ok'}]
</code></pre>
<h3 id="spread"><a class="header" href="#spread">Spread</a></h3>
<p>The Spread Operator (<code>...</code>, sometimes known as &quot;splat&quot;)
can be used to directly flatten/unnest one collection
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/searchindex.json

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion docs/sql/data_types.html
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ <h2 id="object"><a class="header" href="#object">OBJECT</a></h2>
<h2 id="dynamic-literals"><a class="header" href="#dynamic-literals">Dynamic Literals</a></h2>
<h3 id="row-literals"><a class="header" href="#row-literals">Row Literals</a></h3>
<p>It is possible return an entire document (row) as a single literal value.
The syntax is akin to Postgres <a href="https://www.postgresql.org/docs/current/rowtypes.html"><code>ROW</code> literals</a>.
The syntax is akin to Postgres
<a href="https://www.postgresql.org/docs/current/rowtypes.html"><code>ROW</code> literals</a>.
Unlike <code>table.*</code>, which pads non-existent columns with <code>NULL</code>,
a row literal returns exactly the schema specified for each individual row.</p>
<ul>
Expand All @@ -306,6 +307,17 @@ <h3 id="row-literals"><a class="header" href="#row-literals">Row Literals</a></h
<p>Example usage:</p>
<pre><code class="language-sql">SELECT { products.* } FROM products;
</code></pre>
<p>As a shorthand, a table's name may be used in the <code>SELECT</code> clause to return
entire rows as documents:</p>
<pre><code class="language-sql">-&gt; SELECT users FROM users;
-- [{'users': {'email': '[email protected]', 'name': 'Patrick'}},
-- {'users': {'email': '[email protected]', 'name': 'Preethi'}}]
</code></pre>
<p>NOTE: When a table contains a column of the same name, the column takes precedence
and a single column is returned, as usual:</p>
<pre><code class="language-sql">-&gt; SELECT status FROM status;
-- [{'status': 'error'}, {'status': 'ok'}]
</code></pre>
<h3 id="spread"><a class="header" href="#spread">Spread</a></h3>
<p>The Spread Operator (<code>...</code>, sometimes known as &quot;splat&quot;)
can be used to directly flatten/unnest one collection
Expand Down
20 changes: 19 additions & 1 deletion src/sql/data_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ Object equality is tested by comparing each key-value pair as an array.
### Row Literals

It is possible return an entire document (row) as a single literal value.
The syntax is akin to Postgres [`ROW` literals](https://www.postgresql.org/docs/current/rowtypes.html).
The syntax is akin to Postgres
[`ROW` literals](https://www.postgresql.org/docs/current/rowtypes.html).
Unlike `table.*`, which pads non-existent columns with `NULL`,
a row literal returns exactly the schema specified for each individual row.

Expand All @@ -167,6 +168,23 @@ Example usage:
SELECT { products.* } FROM products;
```

As a shorthand, a table's name may be used in the `SELECT` clause to return
entire rows as documents:

```sql
-> SELECT users FROM users;
-- [{'users': {'email': '[email protected]', 'name': 'Patrick'}},
-- {'users': {'email': '[email protected]', 'name': 'Preethi'}}]
```

NOTE: When a table contains a column of the same name, the column takes precedence
and a single column is returned, as usual:

```sql
-> SELECT status FROM status;
-- [{'status': 'error'}, {'status': 'ok'}]
```

### Spread

The Spread Operator (`...`, sometimes known as "splat")
Expand Down

0 comments on commit c2ffe4f

Please sign in to comment.