Fix missing space before WHERE in `GRAPH_TABLE` deparse

From: Chauhan Dhruv <chauhandhruv351(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: peter(at)eisentraut(dot)org, ashutosh(dot)bapat(dot)oss(at)gmail(dot)com
Subject: Fix missing space before WHERE in `GRAPH_TABLE` deparse
Date: 2026-07-25 09:27:36
Message-ID: CANWwWcpHb0h7tg6otRnL-FV83jwQpAiyw1bhvv8T78kpwZ-0ow@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

*Issue:*
The `get_graph_pattern_def()` function omits a leading space before the
WHERE keyword when a GRAPH_TABLE graph pattern includes a WHERE clause.
This produces incorrectly formatted SQL during reverse-parsing. e.g.

... (o IS orders)WHERE (c.address = 'US'::text) COLUMNS ...

Notice the missing space between ) and WHERE.

*Root Cause:*
The pattern-level WHERE deparse doesn't add a leading space, while the
element-level WHERE deparse already does. This inconsistency creates
malformed output.

*Solution:*
The patch changes the pattern-level branch to emit " WHERE " (with leading
space) instead of "WHERE ", matching the element-level behavior. Although
the SQL still re-parses correctly (making this cosmetic), the formatted
output is now correct.

Also adds a regression test for whole-pattern WHERE clauses. make check is
green. Patch is against master.

Thanks,
Dhruv Chauhan

Attachment Content-Type Size
v1-0001-Fix-missing-space-before-WHERE-in-GRAPH_TABLE-dep.patch application/x-patch 3.9 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2026-07-25 10:15:25 Re: Allow pg_read_all_stats to see database size in \l+
Previous Message Michael Paquier 2026-07-25 09:22:55 Re: NULL pointer dereference in syslogger with load_libraries() and -DEXEC_BACKEND at startup