Re: Fix missing space before WHERE in `GRAPH_TABLE` deparse

From: Chauhan Dhruv <chauhandhruv351(at)gmail(dot)com>
To: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, peter(at)eisentraut(dot)org
Subject: Re: Fix missing space before WHERE in `GRAPH_TABLE` deparse
Date: 2026-07-30 11:20:47
Message-ID: CANWwWcpXigbBjDFY_8XGkrST+PO=o2xWu+UBq=HJpLr=FZ2TsQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thanks for the review :)

> Instead of creating another view, I would try to add the WHERE clause in
customer_us definition itself.

Great idea! Done in attached v2. The whole-pattern WHERE clause is now
part of the existing
customers_us definition, so there is no extra view. The predicate
(p.price > 0) is deliberately trivial; as you say, the view is not
queried anywhere, so only its deparsed definition matters.
I also updated the comment above the view to mention that it covers
WHERE clauses both on pattern elements and on the whole pattern.

> Further, we usually don't drop any objects created by this test so that
they can be tested in the 002_pg_upgrade test. Please observe that
customer_us view is not dropped

hmm makes sense, will take care of it

v2 patch is attached.

Regards,
Dhruv

On Thu, 30 Jul 2026 at 08:32, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
wrote:

>
>
> On Sat, Jul 25, 2026 at 2:57 PM Chauhan Dhruv <chauhandhruv351(at)gmail(dot)com>
> wrote:
>
>> 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.
>>
>>
> I wouldn't call it "incorrectly formatted SQL" since it gets parsed
> without any error and has the same semantics as with space. I agree that
> the deparsed string is not readable. The fix looks good to me.
>
>
>> Also adds a regression test for whole-pattern WHERE clauses. make check is
>> green. Patch is against master.
>>
>>
> Instead of creating another view, I would try to add the WHERE clause in
> customer_us definition itself. I don't think we can add a WHERE clause
> which has any meaningful effect on the contents on the view. It will still
> show the effect of deparsing and since the view is not used in any query,
> its actual contents can be ignored.
>
> Further, we usually don't drop any objects created by this test so that
> they can be tested in the 002_pg_upgrade test. Please observe that
> customer_us view is not dropped.
>
> --
> Best Wishes,
> Ashutosh Bapat
>

Attachment Content-Type Size
v2-0001-Fix-missing-space-before-WHERE-in-GRAPH_TABLE-dep.patch text/x-patch 9.4 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ranier Vilela 2026-07-30 11:20:53 Re: lazy_scan_heap: avoid vacuum block, already vacuumed (src/backend/access/heap/vacuumlazy.c)
Previous Message Hannu Krosing 2026-07-30 11:16:36 Re: Support for 8-byte TOAST values, round two