Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1maOZc-0006cA-BQ for pgsql-bugs@arkaria.postgresql.org; Tue, 12 Oct 2021 20:40:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1maOZb-0006nj-AS for pgsql-bugs@arkaria.postgresql.org; Tue, 12 Oct 2021 20:40:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1maOZb-0006na-3v for pgsql-bugs@lists.postgresql.org; Tue, 12 Oct 2021 20:40:31 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1maOZX-0000b0-VS for pgsql-bugs@lists.postgresql.org; Tue, 12 Oct 2021 20:40:30 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 19CKePbg593011; Tue, 12 Oct 2021 16:40:25 -0400 From: Tom Lane To: karllos88@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17225: Query with CTE failed after upgrade Postgres from 11 to 12/13 In-reply-to: <17225-15393593a2d11003@postgresql.org> References: <17225-15393593a2d11003@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Tue, 12 Oct 2021 18:57:21 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <593009.1634071225.1@sss.pgh.pa.us> Date: Tue, 12 Oct 2021 16:40:25 -0400 Message-ID: <593010.1634071225@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > PostgreSQL version: 12.0 If the server is really 12.0, you'd be well advised to update to 12.latest (currently 12.8). We made some changes to CTE support in v12, and I recall that there were some early bugs. > After upgrading Postgres I have a weird error with SELECT query. > ERROR: invalid input syntax for type integer: "36-004" > Query works on previous DB version and now doesn't. Query use a lot of CTE > (To be more specific - 8) and looks like: > ... > What's interesting if the last one CTE (last_inspection_info) will be > replaced with FROM, query runs: Hm. My first thought about this is that this is a silent behavior change resulting from the fact that we no longer materialize CTEs by default, but inline them into the calling query if that wouldn't result in multiple evaluations. That change could translate into the observed error if some cast-to-integer is being applied on a row where it wasn't before. Now, the query change you describe here amounts to manually inlining that one CTE, so that particular CTE doesn't seem to be the cause of the problem. But one of the other CTEs you didn't show us might be. I'd suggest seeing whether the behavior changes when you attach MATERIALIZED keywords to the other CTEs. That'd at least help localize the issue. regards, tom lane