Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1trvF4-00Bc3h-8z for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Mar 2025 08:45:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1trvF2-00BJMJ-Nv for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Mar 2025 08:45:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1trvF2-00BJHf-E4 for pgsql-bugs@lists.postgresql.org; Tue, 11 Mar 2025 08:45:36 +0000 Received: from flooble.net ([96.126.96.250]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1trvF0-002C0q-23 for pgsql-bugs@lists.postgresql.org; Tue, 11 Mar 2025 08:45:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flooble.net; s=202307; t=1741682733; bh=NgA9ZjPcdK33WskIuTul/NpyOKgesMQDR6x/L3kLfpM=; h=Date:From:To:Subject:From; b=EWWyHKLnFPXCQHQXO5o9yvoK6aqaCv4+kZBv0B5uuhesMcJzkCzrGzG/L9bMejAfM J+YwT7YSCfe7qgi4DzwEqS0QC2a0g+vLwBEcIAdXHP6yBiLq1g7svZxeWGDgmHEMYR LmOnU6wK7Sj6fP6IcklYLK2fkXurmlkVJxq2kmBRgNGA2403NZKpmHADJ9hD0xARC2 jbJyuraryzY8knIwO+cUwIa927W1Qn2LOWFkChCQLyNRmm7sPc/s67aVlLbWeBeC+q 03RvefXLtIeBqR8dlABCN/hio8JMHGHrW+63GJ8AbF2KkUW+yROFhu+hVN12tZP2vR 9Xn0wJ59H+Vkw== Received: by flooble.net (Postfix, from userid 1000) id 494931552E; Tue, 11 Mar 2025 19:45:33 +1100 (AEDT) Date: Tue, 11 Mar 2025 19:45:33 +1100 From: Peter Wright To: pgsql-bugs@lists.postgresql.org Subject: Unqualified name not resolved in function called from materialized view (17.4) Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: Peter Wright List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PostgreSQL version: 17.4 Operating system: Ubuntu 24.04, x86_64, kernel 6.8.0-51-generic Description: Given a file "break_it.sql" containing this SQL: SELECT version(); CREATE VIEW things AS SELECT 1 AS id, 'rock' AS thing_name; CREATE FUNCTION num_things() RETURNS INTEGER AS $$ SELECT COUNT(1) FROM things; $$ LANGUAGE SQL STABLE; CREATE MATERIALIZED VIEW thing_report AS SELECT num_things() AS number_of_things; Running the following commands with the environment pointing at a PostgreSQL 17.4 server: dropdb demo 2> /dev/null ; createdb demo && psql -d demo -f break_it.sql ...produces an error on line 4: relation "things" does not exist. Full output (indented two spaces): version ----------------------------------------------------------------------------------------------------------------------------------- PostgreSQL 17.4 (Ubuntu 17.4-1.pgdg24.04+2) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0, 64-bit (1 row) CREATE VIEW CREATE FUNCTION psql:break_it.sql:4: ERROR: relation "things" does not exist LINE 1: SELECT COUNT(1) FROM things; ^ QUERY: SELECT COUNT(1) FROM things; CONTEXT: SQL function "num_things" during inlining Running the same commands with the environment pointing at a PostgreSQL 16.8 server does *not* report an error (and the materialized view is created): version ----------------------------------------------------------------------------------------------------------------------------------- PostgreSQL 16.8 (Ubuntu 16.8-1.pgdg24.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0, 64-bit (1 row) CREATE VIEW CREATE FUNCTION SELECT 1 Similarly, the same test on PostgreSQL 15.10 does not report an error (and the materialized view is created): version ------------------------------------------------------------------------------------------------------------------------------------- PostgreSQL 15.10 (Ubuntu 15.10-1.pgdg24.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0, 64-bit (1 row) CREATE VIEW CREATE FUNCTION SELECT 1 But if I change the third line of "break_it.sql" to use the namespace-qualified name "public.things": CREATE FUNCTION num_things() RETURNS INTEGER AS $$ SELECT COUNT(1) FROM public.things; $$ LANGUAGE SQL STABLE; ...then it works as expected under 17.4 without any error: version ----------------------------------------------------------------------------------------------------------------------------------- PostgreSQL 17.4 (Ubuntu 17.4-1.pgdg24.04+2) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0, 64-bit (1 row) CREATE VIEW CREATE FUNCTION SELECT 1 Pete. -- "I'm an Igor, thur. We don't athk quethtionth." "Really? Why not?" "I don't know, thur. I didn't athk." -- "Making Money", Terry Pratchett