Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gW1Nh-0005j8-3d for pgsql-bugs@arkaria.postgresql.org; Sun, 09 Dec 2018 15:52:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gW1Ne-0006BP-Ri for pgsql-bugs@arkaria.postgresql.org; Sun, 09 Dec 2018 15:52:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gW1Ne-0006Aw-Lm for pgsql-bugs@lists.postgresql.org; Sun, 09 Dec 2018 15:52:30 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gW1Nc-0006rW-La for pgsql-bugs@lists.postgresql.org; Sun, 09 Dec 2018 15:52:30 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id wB9FqP2S011116; Sun, 9 Dec 2018 10:52:25 -0500 From: Tom Lane To: taylor@youneedabudget.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15544: Unexpected: "Returned record type does not match expected record type" after ALTER TABLE In-reply-to: <15544-d64a392db4c763ee@postgresql.org> References: <15544-d64a392db4c763ee@postgresql.org> Comments: In-reply-to =?utf-8?q?PG_Bug_reporting_form?= message dated "Sun, 09 Dec 2018 02:30:07 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <11114.1544370745.1@sss.pgh.pa.us> Date: Sun, 09 Dec 2018 10:52:25 -0500 Message-ID: <11115.1544370745@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =?utf-8?q?PG_Bug_reporting_form?= writes: > If you define a function to return a type of "", and then > alter the table to add a column, that function will immediately begin to > throw an error: "Returned record type does not match expected record type". > This error is not present on any new connections to the database. Yeah, plpgsql has historically been unfriendly to intrasession changes in the rowtypes of composite-typed variables or parameters, because it sets up internal data structures that depend on those details and doesn't have a way to update them. This is improved in v11 --- I won't claim it's perfect yet, but at least it seems to handle this example without problems. Prior to v11, you'd have to start a new session or do CREATE OR REPLACE FUNCTION to make this work. > The only way to fix the issue and use the function again is disconnect and > reconnect to the database (new sessions work fine). This leads me to believe > that there is a cached definition of this table type that is not being > refreshed when the table is altered. It's worth noting that when this > happened to us, not even dropping and recreating the function appeared to be > enough to fix the issue on existing connections. Really? Replacing the function ought to be enough, I should think (and it is, when I try your example on v10). I'd be interested to see a fleshed-out example where it isn't. regards, tom lane