BUG #18803: ERROR: wrong varnullingrels (b) (expected (b 4)) for Var 2/1 - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #18803: ERROR: wrong varnullingrels (b) (expected (b 4)) for Var 2/1
Date
Msg-id 18803-27d209f78dff2d2b@postgresql.org
Whole thread Raw
Responses Re: BUG #18803: ERROR: wrong varnullingrels (b) (expected (b 4)) for Var 2/1
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      18803
Logged by:          Marko Tiikkaja
Email address:      marko@joh.to
PostgreSQL version: 16.6
Operating system:   Linux
Description:

Given this schema:

BEGIN;
CREATE TABLE Users();
CREATE TABLE Orders(MessageID text);
CREATE TABLE Transfers (TransferID bigint);
COMMIT;


Running this query:

DO $$
BEGIN

EXECUTE $SQL$
    SELECT
        CASE WHEN $1 < 1
            THEN 1
            ELSE sum(1) OVER ()
        END AS Total,
        MessageID
    FROM (
        SELECT
            coalesce(
                ECR.MessageID,
                Orders.MessageID
            ) AS MessageID
        FROM Orders
        LEFT JOIN LATERAL (
            SELECT
                Transfers.TransferID || Orders.MessageID AS MessageID
            FROM Transfers
        ) ECR ON TRUE
    ) Txn
$SQL$
    USING 1;

END
$$;

produces the following error:

ERROR:  wrong varnullingrels (b) (expected (b 4)) for Var 2/1

(where the "1" seems to correspond to the pg_attribute.attnum of
Orders.MessageID)


pgsql-bugs by date:

Previous
From: Virender Singla
Date:
Subject: Major Version Upgrade failure due to orphan roles entries in catalog
Next
From: Laurenz Albe
Date:
Subject: Re: Major Version Upgrade failure due to orphan roles entries in catalog