public inbox for [email protected]  
help / color / mirror / Atom feed
From: Zsolt Parragi <[email protected]>
To: Tatsuo Ishii <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Subject: Re: Row pattern recognition
Date: Wed, 11 Mar 2026 22:39:58 +0000
Message-ID: <CAN4CZFOEpz6vXitAkcCGixzAzp4uRRahyScWixKQZU=K4tngtQ@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CAAAe_zBdtRuAfyEX6eqtprY8ejGXqo6ndrpy0LPEHSzGWDvpxw@mail.gmail.com>
	<[email protected]>
	<CAAAe_zCkpYn7qh=chxVLo4-HG8D57RwxhUq-c9zrYvZVtdDgeA@mail.gmail.com>
	<[email protected]>

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.





reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Row pattern recognition
  In-Reply-To: <CAN4CZFOEpz6vXitAkcCGixzAzp4uRRahyScWixKQZU=K4tngtQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox