Re: BUG #14289: Potential bug: "invalid attribute number" when dblink result is assigned in PL/PGSQL - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #14289: Potential bug: "invalid attribute number" when dblink result is assigned in PL/PGSQL
Date
Msg-id 19568.1471546317@sss.pgh.pa.us
Whole thread Raw
In response to BUG #14289: Potential bug: "invalid attribute number" when dblink result is assigned in PL/PGSQL  (m.overmeyer@yahoo.ca)
List pgsql-bugs
m.overmeyer@yahoo.ca writes:
> I believe I may have found a bug in PL/PGSQL or dblink.

So you did.  Fixed, thanks.

For the archives' sake, the test case looked like

------
create extension dblink;

create table test_table
(
  username text primary key
);

INSERT INTO test_table VALUES ('test_user');

CREATE OR REPLACE FUNCTION test_assignment(primary_key_attnums int2vector)
  RETURNS text AS
$BODY$
DECLARE
    results text;
BEGIN
    -- This doesn't work:
    results := dblink_build_sql_delete('test_table', primary_key_attnums, 1, ARRAY['test_user']::text[]);

    -- But this one (use value instead of parameter) does work:
    --results := dblink_build_sql_delete('test_table', '1'::int2vector, 1, ARRAY['test_user']::text[]);

    --And so does this one:
    -- SELECT dblink_build_sql_delete('test_table', primary_key_attnums, 1, ARRAY['test_user']::text[]) INTO results;

    return results;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;

SELECT test_assignment('1'::int2vector);
-----

and the problem was that plpgsql thought it could convert the int2vector
argument into an "expanded array".  But int2vector doesn't allow toasting
so a fortiori it can't handle being expanded.

            regards, tom lane

pgsql-bugs by date:

Previous
From: Joe Conway
Date:
Subject: Re: BUG #14289: Potential bug: "invalid attribute number" when dblink result is assigned in PL/PGSQL
Next
From: rotten@windfish.net
Date:
Subject: BUG #14290: materialized view refresh doesn't use temp_tablespace