Thread

  1. BUG #18803: ERROR: wrong varnullingrels (b) (expected (b 4)) for Var 2/1

    PG Bug reporting form <noreply@postgresql.org> — 2025-02-11T14:15:51Z

    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)
    
    
  2. Re: BUG #18803: ERROR: wrong varnullingrels (b) (expected (b 4)) for Var 2/1

    Tom Lane <tgl@sss.pgh.pa.us> — 2025-02-11T15:33:38Z

    PG Bug reporting form <noreply@postgresql.org> writes:
    > Given this schema:
    > ...
    > Running this query:
    > ...
    > produces the following error:
    > ERROR:  wrong varnullingrels (b) (expected (b 4)) for Var 2/1
    
    Thanks for the clear report!  We've seen a few variants of this,
    and apparently yours is among the cases that are recently fixed.
    Trying this example on a fresh 16-tip build (more or less 16.7)
    just emits
    
    DO
    
    			regards, tom lane
    
    
    
    
  3. Re: BUG #18803: ERROR: wrong varnullingrels (b) (expected (b 4)) for Var 2/1

    Marko Tiikkaja <marko@joh.to> — 2025-02-11T20:55:32Z

    Hi Tom,
    
    On Tue, Feb 11, 2025 at 5:33 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
    > Thanks for the clear report!  We've seen a few variants of this,
    > and apparently yours is among the cases that are recently fixed.
    > Trying this example on a fresh 16-tip build (more or less 16.7)
    > just emits
    
    That would be my bad.  I git grep'd the 16 branch but I thought it was
    unrelated.  Thanks for the confirmation!
    
    
    .m