| From: | Tatsuo Ishii <ishii(at)postgresql(dot)org> |
|---|---|
| To: | assam258(at)gmail(dot)com, zsolt(dot)parragi(at)percona(dot)com, 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, li(dot)evan(dot)chao(at)gmail(dot)com |
| Cc: | pgsql-hackers(at)postgresql(dot)org |
| Subject: | Re: Row pattern recognition |
| Date: | 2026-05-05 00:01:24 |
| Message-ID: | 20260505.090124.365339750969814137.ishii@postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
> Attached is the v47 patches for Row pattern recognition (SQL/RPR).
v47 starts to check whether range variable qualified expressions are
used in DEFINE clause. If used, raise an error. This is good because
we don't support the syntax yet (pattern variable range var), or it's
prohibited (from clause range var). However, the error message may not
be appropreate for the case when complex data type is involved.
CREATE TEMP TABLE item (name TEXT, amount INT);
CREATE TABLE
CREATE TEMP TABLE sales(items item);
CREATE TABLE
SELECT (items).name, (items).amount, count(*) OVER w
FROM sales WINDOW w AS (
ORDER BY (items).name
ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
AFTER MATCH SKIP PAST LAST ROW
PATTERN (A+)
DEFINE A AS (A.items).amount > 10
);
ERROR: pattern variable qualified column reference "a.items" is not supported in DEFINE clause
LINE 7: DEFINE A AS (A.items).amount > 10
^
If I change the DEFINE clause to:
DEFINE A AS (sales.items).amount > 10
I get:
ERROR: range variable qualified column reference "sales.items" is not allowed in DEFINE clause
LINE 8: DEFINE A AS (sales.items).amount > 10
^
In both cases, "a.items" or "sales.items" in the error messages are
not column names, therefore the wording "column reference" in the
error messages are not appropriate.
The checks are in transformColumnRef(). Its argument "ColumnRef
*cref->fields" is a list of column ref fields in DEFINE expression in
the raw parse tree. Usually it's something like range_var.col_name or
just col_name etc. So it works. However when complex data types are
involved, cref->fields is something like sales.items. No col_name
included. In this case, ColumnRef is under Indirection node, and the
col_name is stored in Indirection->indirection, not in ColumnRef.
Therefore there's no way for transformColumnRef() to know the col_name.
In order to fix the issue, I think we need to add code to understand
range var qualification form "A.item" or "sales.items" in complex data
types case. But is it worth the trouble? The reword is just nicer
error messages. If we support MEASURES, the code is useful. But so far
we have decided to not support it in the first cut of RPR.
Maybe we should just change the error messages something like below
for now?
ERROR: pattern variable qualified expression "a.items" is not supported in DEFINE clause
ERROR: range variable qualified expression "sales.items" is not allowed in DEFINE clause
Regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp
| From | Date | Subject | |
|---|---|---|---|
| Next Message | SATYANARAYANA NARLAPURAM | 2026-05-05 01:11:11 | [Patch] Omit virtual generated columns from test_decoding output |
| Previous Message | Kirill Reshke | 2026-05-04 22:20:46 | Re: small cleanup for s_lock.h |