Re: Row pattern recognition

From: Tatsuo Ishii <ishii(at)postgresql(dot)org>
To: assam258(at)gmail(dot)com
Cc: sjjang112233(at)gmail(dot)com, vik(at)postgresfriends(dot)org, er(at)xs4all(dot)nl, jacob(dot)champion(at)enterprisedb(dot)com, david(dot)g(dot)johnston(at)gmail(dot)com, peter(at)eisentraut(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Row pattern recognition
Date: 2026-03-09 05:22:02
Message-ID: 20260309.142202.1739855502263731478.ishii@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Henson,

>> Excellnt findings! BTW, I realized that we cannot use $1 of function
>> in PATTERN clause like: A{$1}.
>>
>> ERROR: 42601: syntax error at or near "$1"
>> LINE 10: PATTERN (A{$1})
>> ^
>> LOCATION: scanner_yyerror, scan.l:1211
>>
>> Should we document somewhere?
>>
>
> The PATTERN quantifier {n} only accepts Iconst (integer literal) in the
> grammar. When a host variable or function parameter is used (e.g.,
> A{$1}), the user gets a generic syntax error.

Ok.

> Oracle accepts broader syntax and validates later, producing an error
> at a later stage rather than a syntax error at parse time.
>
> PostgreSQL itself already has precedent for this pattern -- in fact,
> within the same window clause, frame offset (ROWS/RANGE/GROUPS) accepts
> a_expr in the grammar and then rejects variables in parse analysis via
> transformFrameOffset() -> checkExprIsVarFree().
>
> I'd lean against documenting this. The SQL standard already defines
> the quantifier bound as <unsigned integer literal>, so there is nothing
> beyond the standard to call out, and documenting what is *not* allowed
> tends to raise questions that wouldn't otherwise occur to users.
>
> Rather, I think accepting a broader grammar and validating later would
> be the more appropriate response, producing a descriptive error like:
>
> "argument of bounded quantifier must be an integer literal"
>
> I can either include this in the current patch set or handle it as a
> separate follow-up after the main series is committed. What do you
> think?

I think handing it as a separate follow-up after the commit is enough
unless other developers complain.

Best regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2026-03-09 05:22:36 Re: Use allocation macros in the logical replication code
Previous Message Chao Li 2026-03-09 05:20:45 Re: Add pg_stat_recovery system view