doc: Reformat SELECT queries using GRAPH_TABLE

Started by Koshino Taiki3 months ago8 messageshackers
Jump to latest
#1Koshino Taiki
koshino@sraoss.co.jp

Hi,

The SELECT queries using GRAPH_TABLE in ddl.sgml and queries.sgml
were written on single long lines, requiring horizontal scrolling.

This patch breaks the queries across multiple lines to improve
readability. This is also consistent with the CREATE PROPERTY GRAPH
statement in the PostgreSQL documentation, which is already formatted
across multiple lines:

https://www.postgresql.org/docs/19/ddl-property-graphs.html

For the placement and indentation of the line breaks in the
GRAPH_TABLE queries, I referred to the example in the "Property Graph
Queries" section of Peter Eisentraut's SQL:2023 overview:

https://peter.eisentraut.org/blog/2023/04/04/sql-2023-is-finished-here-is-whats-new

The example is formatted as follows:

SELECT owner_name,
SUM(amount) AS total_transacted
FROM financial_transactions GRAPH_TABLE (
MATCH (p:person WHERE p.name = 'Alice')
-[:ownerof]-> (:account)
-[t:transaction]- (:account)
<-[:ownerof]- (owner:person|company)
COLUMNS (owner.name AS owner_name, t.amount AS amount)
) AS ft
GROUP BY owner_name;

Best regards,
Taiki Koshino

Taiki Koshino<koshino@sraoss.co.jp>
SRA OSS K.K.
TEL: 03-5979-2701 FAX: 03-5979-2702
URL: https://www.sraoss.co.jp/

Attachments:

t253509_1
v1-0001-doc-Reformat-SELECT-queries-using-GRAPH_TABLE.patchapplication/octet-stream; name=v1-0001-doc-Reformat-SELECT-queries-using-GRAPH_TABLE.patchDownload+18-4
#2Ashutosh Bapat
ashutosh.bapat.oss@gmail.com
In reply to: Koshino Taiki (#1)
Re: doc: Reformat SELECT queries using GRAPH_TABLE

On Fri, Aug 21, 2026 at 12:35 PM Koshino Taiki <koshino@sraoss.co.jp> wrote:

Hi,

The SELECT queries using GRAPH_TABLE in ddl.sgml and queries.sgml
were written on single long lines, requiring horizontal scrolling.

This patch breaks the queries across multiple lines to improve
readability. This is also consistent with the CREATE PROPERTY GRAPH
statement in the PostgreSQL documentation, which is already formatted
across multiple lines:

I agree that spreading this query over multiple lines would be better
but the way it's done in the patch doesn't feel right. It leaves the
first vertex pattern on the original line along with GRAPH_TABLE and
MATCH. The rest of the path pattern is moved to the next line. This
make it hard to grasp the whole path pattern in one go. I think we
should try leaving GRAPH_TABLE ( ... on the original line and move the
whole MATCH clause to the next line and COLUMNS to another line.
However the path pattern would still be long enough that it would
require scrolling. But we should try that first.

If we break the path pattern into multiple lines, the problem there is
whether to keep the arrows or connecting lines along with the vertex
or with the edge. Since the standard defines an edge pattern as the
arrow/connector along with the brackets, it might be better to keep
the arrows and connectors with the edge pattern. Formatting the query
as below might be better.

SELECT customer_name FROM GRAPH_TABLE (myshop

MATCH (c IS customers)

-[IS customer_orders]->

(o IS orders WHERE o.ordered_when =
current_date)

COLUMNS (c.name AS customer_name));

But with that one has to read multiple lines to understand the path
pattern. So I would avoid it for a small pattern like this.

--
Best Wishes,
Ashutosh Bapat

#3Koshino Taiki
koshino@sraoss.co.jp
In reply to: Ashutosh Bapat (#2)
Re: doc: Reformat SELECT queries using GRAPH_TABLE

I agree that spreading this query over multiple lines would be better
but the way it's done in the patch doesn't feel right. It leaves the
first vertex pattern on the original line along with GRAPH_TABLE and
MATCH. The rest of the path pattern is moved to the next line. This
make it hard to grasp the whole path pattern in one go. I think we
should try leaving GRAPH_TABLE ( ... on the original line and move the
whole MATCH clause to the next line and COLUMNS to another line.
However the path pattern would still be long enough that it would
require scrolling. But we should try that first.

If we break the path pattern into multiple lines, the problem there is
whether to keep the arrows or connecting lines along with the vertex
or with the edge. Since the standard defines an edge pattern as the
arrow/connector along with the brackets, it might be better to keep
the arrows and connectors with the edge pattern. Formatting the query
as below might be better.

SELECT customer_name FROM GRAPH_TABLE (myshop

MATCH (c IS customers)

-[IS customer_orders]->

(o IS orders WHERE o.ordered_when =
current_date)

COLUMNS (c.name AS customer_name));

But with that one has to read multiple lines to understand the path
pattern. So I would avoid it for a small pattern like this.

Hi,

Thanks for the detailed feedback.
I put together a v2 patch that follows the approach you suggested:
keeping GRAPH_TABLE ( on the opening line, moving the whole MATCH
clause to its own line, and putting COLUMNS on another line, for example:

SELECT customer_name FROM GRAPH_TABLE (myshop
MATCH (c IS customers)
-[IS customer_orders]->
(o IS orders WHERE o.ordered_when = current_date)
COLUMNS (c.name AS customer_name));

I've confirmed that with this formatting,
each line stays short enough that
horizontal scrolling is unlikely to be needed,
while the path pattern is still easy to read as a whole.

I applied the same formatting consistently to both occurrences
in ddl.sgml and the one in queries.sgml. Attached is the v2 patch.
Let me know if this matches what you had in mind,
or if you would prefer a different line break for the path pattern.

Regards,
Taiki Koshino

Taiki Koshino<koshino@sraoss.co.jp>
SRA OSS K.K.
TEL: 03-5979-2701 FAX: 03-5979-2702
URL: https://www.sraoss.co.jp/

________________________________

On Fri, Aug 21, 2026 at 12:35 PM Koshino Taiki <koshino@sraoss.co.jp> wrote:

Hi,

The SELECT queries using GRAPH_TABLE in ddl.sgml and queries.sgml
were written on single long lines, requiring horizontal scrolling.

This patch breaks the queries across multiple lines to improve
readability. This is also consistent with the CREATE PROPERTY GRAPH
statement in the PostgreSQL documentation, which is already formatted
across multiple lines:

I agree that spreading this query over multiple lines would be better
but the way it's done in the patch doesn't feel right. It leaves the
first vertex pattern on the original line along with GRAPH_TABLE and
MATCH. The rest of the path pattern is moved to the next line. This
make it hard to grasp the whole path pattern in one go. I think we
should try leaving GRAPH_TABLE ( ... on the original line and move the
whole MATCH clause to the next line and COLUMNS to another line.
However the path pattern would still be long enough that it would
require scrolling. But we should try that first.

If we break the path pattern into multiple lines, the problem there is
whether to keep the arrows or connecting lines along with the vertex
or with the edge. Since the standard defines an edge pattern as the
arrow/connector along with the brackets, it might be better to keep
the arrows and connectors with the edge pattern. Formatting the query
as below might be better.

SELECT customer_name FROM GRAPH_TABLE (myshop

MATCH (c IS customers)

-[IS customer_orders]->

(o IS orders WHERE o.ordered_when =
current_date)

COLUMNS (c.name AS customer_name));

But with that one has to read multiple lines to understand the path
pattern. So I would avoid it for a small pattern like this.

--
Best Wishes,
Ashutosh Bapat

Attachments:

t253509_3
v2-0001-doc-Reformat-SELECT-queries-using-GRAPH_TABLE.patchapplication/octet-stream; name=v2-0001-doc-Reformat-SELECT-queries-using-GRAPH_TABLE.patchDownload+15-4
#4Fujii Masao
masao.fujii@gmail.com
In reply to: Koshino Taiki (#3)
Re: doc: Reformat SELECT queries using GRAPH_TABLE

On Tue, Aug 25, 2026 at 10:33 AM Koshino Taiki <koshino@sraoss.co.jp> wrote:

I put together a v2 patch that follows the approach you suggested:
keeping GRAPH_TABLE ( on the opening line, moving the whole MATCH
clause to its own line, and putting COLUMNS on another line, for example:

SELECT customer_name FROM GRAPH_TABLE (myshop
MATCH (c IS customers)
-[IS customer_orders]->
(o IS orders WHERE o.ordered_when = current_date)
COLUMNS (c.name AS customer_name));

Splitting the path pattern across three lines is really necessary?
Even without doing that, the full MATCH line would still be around
90–100 characters, which seems readable enough.

There is another nearby GRAPH_TABLE example in queries.sgml that
uses a different formatting style. If this patch is also intended to
establish a clearer formatting style for GRAPH_TABLE examples,
isn't it better to adjust that example as well?

Regards,

--
Fujii Masao

#5Koshino Taiki
koshino@sraoss.co.jp
In reply to: Fujii Masao (#4)
Re: doc: Reformat SELECT queries using GRAPH_TABLE

Splitting the path pattern across three lines is really necessary?
Even without doing that, the full MATCH line would still be around
90–100 characters, which seems readable enough.

There is another nearby GRAPH_TABLE example in queries.sgml that
uses a different formatting style. If this patch is also intended to
establish a clearer formatting style for GRAPH_TABLE examples,
isn't it better to adjust that example as well?

Hi,

I agree that splitting the path pattern into three lines wasn't really necessary;
even without it, the MATCH line stays around 90 to 100 characters, which is readable enough.
I've put together a patch that keeps GRAPH_TABLE ( on the opening line,
MATCH on one line, and COLUMNS on another,
and applied the same style to the other GRAPH_TABLE examples
in ddl.sgml and queries.sgml for consistency, for example:

SELECT customer_name FROM GRAPH_TABLE (myshop
MATCH (c IS customers)-[IS customer_orders]->(o IS orders WHERE o.ordered_when = current_date)
COLUMNS (c.name AS customer_name));

Separately, I noticed the relational query below the first GRAPH_TABLE example
in ddl.sgml is also quite long (about 150 characters).
I wonder if it's worth breaking that one too, maybe right before WHERE, like:

SELECT customers.name FROM customers JOIN customer_orders USING (customer_id) JOIN orders USING (order_id)
WHERE orders.ordered_when = current_date;

I wasn't sure whether this should be part of the same patch,
so I've attached two versions: v3 leaves it untouched,
and v4 includes the change. Let me know which you'd prefer.

Regards,
Taiki Koshino

Taiki Koshino<koshino@sraoss.co.jp>
SRA OSS K.K.
TEL: 03-5979-2701 FAX: 03-5979-2702
URL: https://www.sraoss.co.jp/

________________________________

On Tue, Aug 25, 2026 at 10:33 AM Koshino Taiki <koshino@sraoss.co.jp> wrote:

I put together a v2 patch that follows the approach you suggested:
keeping GRAPH_TABLE ( on the opening line, moving the whole MATCH
clause to its own line, and putting COLUMNS on another line, for example:

SELECT customer_name FROM GRAPH_TABLE (myshop
MATCH (c IS customers)
-[IS customer_orders]->
(o IS orders WHERE o.ordered_when = current_date)
COLUMNS (c.name AS customer_name));

Splitting the path pattern across three lines is really necessary?
Even without doing that, the full MATCH line would still be around
90–100 characters, which seems readable enough.

There is another nearby GRAPH_TABLE example in queries.sgml that
uses a different formatting style. If this patch is also intended to
establish a clearer formatting style for GRAPH_TABLE examples,
isn't it better to adjust that example as well?

Regards,

--
Fujii Masao

Attachments:

t253509_5
v4-0001-doc-Reformat-SELECT-queries-using-GRAPH_TABLE.patchapplication/octet-stream; name=v4-0001-doc-Reformat-SELECT-queries-using-GRAPH_TABLE.patchDownload+20-9
v3-0001-doc-Reformat-SELECT-queries-using-GRAPH_TABLE.patchapplication/octet-stream; name=v3-0001-doc-Reformat-SELECT-queries-using-GRAPH_TABLE.patchDownload+18-8
#6Fujii Masao
masao.fujii@gmail.com
In reply to: Koshino Taiki (#5)
Re: doc: Reformat SELECT queries using GRAPH_TABLE

On Wed, Aug 26, 2026 at 10:25 AM Koshino Taiki <koshino@sraoss.co.jp> wrote:

I wasn't sure whether this should be part of the same patch,
so I've attached two versions: v3 leaves it untouched,
and v4 includes the change. Let me know which you'd prefer.

I think v3 is preferable. The corresponding relational query in
ddl.sgml is also long, but it isn't a GRAPH_TABLE example, so I think
we should keep this patch focused on reformatting GRAPH_TABLE examples.

If necessary, you could start a separate thread about reformatting long
query examples in the documentation. It might be better to review all
such examples and reformat them consistently, rather than addressing
only the long query in ddl.sgml mentioned here.

-GRAPH_TABLE (mygraph MATCH (p IS person)-[h IS has]->(a IS account)
-             COLUMNS (p.name AS person_name, h.since AS
has_account_since, a.num AS account_number)
+GRAPH_TABLE (mygraph
+    MATCH (p IS person)-[h IS has]->(a IS account)
+    COLUMNS (p.name AS person_name, h.since AS has_account_since,
a.num AS account_number)

Regarding v3 patch, this example in queries.sgml seems to be missing
the closing parenthesis for GRAPH_TABLE. That is, I think ")" should be
added at the end of the example above.

BTW, it would be helpful if you could trim the quoted text in your replies,
leaving only the parts relevant to your response. There's no need to
include the entire previous email at the bottom.

Regards,

--
Fujii Masao

#7Koshino Taiki
koshino@sraoss.co.jp
In reply to: Fujii Masao (#6)
Re: doc: Reformat SELECT queries using GRAPH_TABLE

I think v3 is preferable. The corresponding relational query in
ddl.sgml is also long, but it isn't a GRAPH_TABLE example, so I think
we should keep this patch focused on reformatting GRAPH_TABLE examples.

Thanks, I agree v3's scope is the right one to go with,
so I'll keep this patch focused on the GRAPH_TABLE examples and
leave the JOIN query and other cases out of scope here.

Regarding v3 patch, this example in queries.sgml seems to be missing
the closing parenthesis for GRAPH_TABLE. That is, I think ")" should be
added at the end of the example above.

I've added the missing closing parenthesis and attached a v5 patch.

Regards,
Taiki Koshino

Taiki Koshino<koshino@sraoss.co.jp>
SRA OSS K.K.
TEL: 03-5979-2701 FAX: 03-5979-2702
URL: https://www.sraoss.co.jp/

________________________________

On Wed, Aug 26, 2026 at 10:25 AM Koshino Taiki <koshino@sraoss.co.jp> wrote:

I wasn't sure whether this should be part of the same patch,
so I've attached two versions: v3 leaves it untouched,
and v4 includes the change. Let me know which you'd prefer.

I think v3 is preferable. The corresponding relational query in
ddl.sgml is also long, but it isn't a GRAPH_TABLE example, so I think
we should keep this patch focused on reformatting GRAPH_TABLE examples.

If necessary, you could start a separate thread about reformatting long
query examples in the documentation. It might be better to review all
such examples and reformat them consistently, rather than addressing
only the long query in ddl.sgml mentioned here.

-GRAPH_TABLE (mygraph MATCH (p IS person)-[h IS has]->(a IS account)
-             COLUMNS (p.name AS person_name, h.since AS
has_account_since, a.num AS account_number)
+GRAPH_TABLE (mygraph
+    MATCH (p IS person)-[h IS has]->(a IS account)
+    COLUMNS (p.name AS person_name, h.since AS has_account_since,
a.num AS account_number)

Regarding v3 patch, this example in queries.sgml seems to be missing
the closing parenthesis for GRAPH_TABLE. That is, I think ")" should be
added at the end of the example above.

BTW, it would be helpful if you could trim the quoted text in your replies,
leaving only the parts relevant to your response. There's no need to
include the entire previous email at the bottom.

Regards,

--
Fujii Masao

Attachments:

t253509_7
v5-0001-doc-Reformat-SELECT-queries-using-GRAPH_TABLE.patchapplication/octet-stream; name=v5-0001-doc-Reformat-SELECT-queries-using-GRAPH_TABLE.patchDownload+18-8
#8Fujii Masao
masao.fujii@gmail.com
In reply to: Koshino Taiki (#7)
Re: doc: Reformat SELECT queries using GRAPH_TABLE

On Fri, Aug 28, 2026 at 2:09 PM Koshino Taiki <koshino@sraoss.co.jp> wrote:

I've added the missing closing parenthesis and attached a v5 patch.

Thanks for updating the patch! I've pushed it.

Regards,

--
Fujii Masao