pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #14470: Dropping a column produces "table row type and query-specified row type do not match" error
2+ messages / 2 participants
[nested] [flat]
* BUG #14470: Dropping a column produces "table row type and query-specified row type do not match" error
@ 2016-12-20 23:33 joan@sanchezsabe.com
0 siblings, 1 reply; 2+ messages in thread
From: joan@sanchezsabe.com @ 2016-12-20 23:33 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 14470
Logged by: Joan Sánchez Sabé
Email address: joan@sanchezsabe.com
PostgreSQL version: 9.6.1
Operating system: Mac OS X 10.12.2
Description:
Steps to reproduce:
CREATE TABLE users
(
id SERIAL PRIMARY KEY,
email TEXT NOT NULL,
column_that_we_will_drop TEXT
) ;
CREATE OR REPLACE FUNCTION fun (_email text)
RETURNS integer AS
$$
-- Need a CTE to produce the error. A 'constant' one suffices.
WITH something_even_if_useless(a) AS
(
VALUES (1)
)
UPDATE
users
SET
id = id
WHERE
-- The CTE needs to be referenced, if the next
-- condition were not in place, the problem is not reproduced
EXISTS (SELECT * FROM something_even_if_useless)
AND email = _email
RETURNING
id
$$
LANGUAGE "sql" ;
At this point, calls to the function such as
SELECT * FROM fun('a@b.com');
Work without problems.
At this point, if we drop one column (not used at all by the previous
function)...
ALTER TABLE users
DROP COLUMN column_that_we_will_drop ;
... this makes the next statement to generate an error
SELECT * FROM fun('a@b.com');
ERROR: table row type and query-specified row type do not match
SQL state: 42804
Detail: Query provides a value for a dropped column at ordinal position 3.
Context: SQL function "fun" statement 1
SELECT * FROM fun('a@b.com');
The function is not explicitly using the "users TABLE" type, and doesn't use
at all the "column_that_we_will_drop". If the function doesn't have a CTE,
or if the CTE itself is not later on used, the error is not produced.
This problem was originally pointed out by @Andy at
http://dba.stackexchange.com/questions/153981/postgresql-column-renaming-reordering-and-side-effects....
I managed to reproduce it with a simpler version.
The bug does not show using PostgreSQL version 9.4.10. [I have no other
versions to check.]
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #14470: Dropping a column produces "table row type and query-specified row type do not match" error
@ 2016-12-21 00:30 Tom Lane <tgl@sss.pgh.pa.us>
parent: joan@sanchezsabe.com
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2016-12-21 00:30 UTC (permalink / raw)
To: joan@sanchezsabe.com; +Cc: pgsql-bugs
joan@sanchezsabe.com writes:
> At this point, if we drop one column (not used at all by the previous
> function)...
> ALTER TABLE users
> DROP COLUMN column_that_we_will_drop ;
> ... this makes the next statement to generate an error
> SELECT * FROM fun('a@b.com');
> ERROR: table row type and query-specified row type do not match
> SQL state: 42804
> Detail: Query provides a value for a dropped column at ordinal position 3.
> Context: SQL function "fun" statement 1
> SELECT * FROM fun('a@b.com');
I can't reproduce this in HEAD or 9.6 branch tip. I believe it was
already fixed by this patch, which went in a bit after 9.6.1:
https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=f4d865f22
But thanks for the report!
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2016-12-21 00:30 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-12-20 23:33 BUG #14470: Dropping a column produces "table row type and query-specified row type do not match" error joan@sanchezsabe.com
2016-12-21 00:30 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox