BUG #14289: Potential bug: "invalid attribute number" when dblink result is assigned in PL/PGSQL

From: m(dot)overmeyer(at)yahoo(dot)ca
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #14289: Potential bug: "invalid attribute number" when dblink result is assigned in PL/PGSQL
Date: 2016-08-18 17:44:14
Message-ID: 20160818174414.1529.37913@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 14289
Logged by: Michael Overmeyer
Email address: m(dot)overmeyer(at)yahoo(dot)ca
PostgreSQL version: 9.5.4
Operating system: CentOS 7, also Docker
Description:

I believe I may have found a bug in PL/PGSQL or dblink. When using the
assignment operator to assign the results of dblink_build_sql_delete to a
variable, it gives me:

psql:pg_bug.sql:37: ERROR: 22023: invalid attribute number -1598
CONTEXT: PL/pgSQL function test_assignment(int2vector) line 6 at
assignment
LOCATION: validate_pkattnums, dblink.c:2851

This does not occur if I do not pass the int2vector as a parameter, nor when
I use the SELECT...INTO syntax.

Steps to reproduce:
1. Download
https://gist.githubusercontent.com/movermeyer/cdc9c997744d97a5cf9471837dff6b4a/raw/b4e7f338834ed35a8f7cb0653f843f5efaec0fef/pg_bug.sql
to "pg_bug.sql"
1. Start a Postgres instance: `docker run -i -t --rm=true -e
POSTGRES_PASSWORD=postgres -p 5432:5432 postgres`
2. Run pg_bug.sql: `PGPASSWORD=postgres psql -U postgres -h 127.0.0.1 -p
5432 -f pg_bug.sql`

Sample output:

CREATE DATABASE
You are now connected to database "test_db" as user "postgres".
CREATE EXTENSION
CREATE TABLE
INSERT 0 1
CREATE FUNCTION
psql:pg_bug.sql:37: ERROR: 22023: invalid attribute number -1598
CONTEXT: PL/pgSQL function test_assignment(int2vector) line 6 at
assignment
LOCATION: validate_pkattnums, dblink.c:2851

Workaround:

Use the SELECT...INTO syntax instead.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Joe Conway 2016-08-18 18:25:27 Re: BUG #14289: Potential bug: "invalid attribute number" when dblink result is assigned in PL/PGSQL
Previous Message Tom Lane 2016-08-18 14:09:06 Re: Re: Re: Re:Re: [BUGS] Re: [BUGS] Return value error of‘to_timestamp’