Re: Row pattern recognition

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: Tatsuo Ishii <ishii(at)postgresql(dot)org>
Cc: assam258(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-11 22:39:58
Message-ID: CAN4CZFOEpz6vXitAkcCGixzAzp4uRRahyScWixKQZU=K4tngtQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello

+ /*
+ * Make sure that the row pattern definition search condition is a boolean
+ * expression.
+ */
+ foreach_ptr(TargetEntry, te, defineClause)
+ (void) coerce_to_boolean(pstate, (Node *) te->expr, "DEFINE");

Isn't this incorrect? I think it should update te->expr, as currently
it is possible to construct queries where this produces unexpected
results.

CREATE TYPE truthyint AS (v int);

CREATE FUNCTION truthyint_to_bool(truthyint) RETURNS boolean AS $$
SELECT ($1).v <> 0;
$$ LANGUAGE SQL IMMUTABLE STRICT;

CREATE CAST (truthyint AS boolean)
WITH FUNCTION truthyint_to_bool(truthyint)
AS ASSIGNMENT;

CREATE TABLE test_coerce (id serial, val truthyint);
INSERT INTO test_coerce VALUES
(1, ROW(1)),
(2, ROW(0)),
(3, ROW(5)),
(4, ROW(0));

SELECT id, val, COUNT(*) OVER w AS cnt
FROM test_coerce
WINDOW w AS (
ORDER BY id
ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
PATTERN (A+)
DEFINE A AS val
)
ORDER BY id;

Same query provides the correct result with a table that has an actual
boolean column.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2026-03-11 22:40:41 Re: Buffer locking is special (hints, checksums, AIO writes)
Previous Message Alexander Korotkov 2026-03-11 22:37:31 Re: Odd code around ginScanToDelete