Re: SQL Property Graph Queries (SQL/PGQ)

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, assam258(at)gmail(dot)com
Cc: Alexander Lakhin <exclusion(at)gmail(dot)com>, Amit Langote <amitlangote09(at)gmail(dot)com>, Junwang Zhao <zhjwpku(at)gmail(dot)com>, Vik Fearing <vik(at)postgresfriends(dot)org>, Ajay Pal <ajay(dot)pal(dot)k(at)gmail(dot)com>, Imran Zaheer <imran(dot)zhir(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: SQL Property Graph Queries (SQL/PGQ)
Date: 2026-03-25 08:57:31
Message-ID: 5fc6e349-0e17-438f-a170-4326f86dbb02@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 23.03.26 16:00, Ashutosh Bapat wrote:
> An empty pattern has no label expression which is equivalent to
> disjunction of all applicable labels. If we add an empty pattern in
> the rewrite phase, we will require its label expression to be resolved
> in the rewrite phase. Looking at the proposed changes for all
> properties reference [1], I am moving towards resolving the label
> expression in the transformation stage itself. So I think it's better
> to add the implicit vertex patterns during the transformation stage to
> be future proof. Rewriter should just then rewrite the patterns into
> joins and unions. Your point is correct that the implicit vertex
> should not be visible in view definition or deparsed query. For that I
> have added a flag implicit to GraphElementPattern.
> GraphElementPatterns with implicit = true are ignored by ruleutils.
> Implemented it that way in the attached patch.
>
> Vertex patterns without an edge pattern in between are not supported
> OTOH. Added an ereport for the same.
>
> I have also added a few tests. I didn't add queries with all the
> patterns you mentioned above. I tested a few by hand and all of them
> worked as expected. Can you please check?

This functionality that you can leave off empty vertex patterns at the
beginning and end is part of the optional feature G047, which we don't
claim to support. So we should reject these path patterns.

>> Separately, while testing various edge patterns I noticed that
>> `<-[]->` (full edge left or right) produces a syntax error:
>>
>> SELECT count(*) FROM GRAPH_TABLE (g1 MATCH ()<-[]->() COLUMNS (1 AS one));
>> ERROR: syntax error at or near "->"
>>
>> Per the standard BNF, this should be valid:
>>
>> <full edge left or right> ::=
>> <left arrow bracket> <element pattern filler> <bracket right arrow>
>>
>> i.e., `<-[]->` = `<-[` + `]->`. This is a separate parser issue,
>> not related to the implicit vertex insertion above.
>
> Yes. That's a grammar issue. gram.y doesn't support it. Peter, do you
> remember or know the reason why we don't support full edge left or
> right? In fact, I am wondering what's the difference between full edge
> left or right and full edge any direction?

<full edge left or right> is part of optional feature G043, which we
don't claim to support.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tender Wang 2026-03-25 09:00:17 Re: Fix "could not find memoization table entry"
Previous Message Jelte Fennema-Nio 2026-03-25 08:54:00 Make \d tablename fast again, regression introduced by 85b7efa1cdd