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 1tTqzZ-00BIDn-Ha for pgsql-general@arkaria.postgresql.org; Fri, 03 Jan 2025 23:22:09 +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 1tTqzY-00644J-9C for pgsql-general@arkaria.postgresql.org; Fri, 03 Jan 2025 23:22:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tTqzX-00641A-UV for pgsql-general@lists.postgresql.org; Fri, 03 Jan 2025 23:22:07 +0000 Received: from gaoxing.magnetkern.de ([167.235.225.147]) by magus.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1tTqzV-0006Ld-37 for pgsql-general@lists.postgresql.org; Fri, 03 Jan 2025 23:22:07 +0000 Received: from titanium.fritz.box (p200300c26f20ef00264bfefffe54b09c.dip0.t-ipconnect.de [IPv6:2003:c2:6f20:ef00:264b:feff:fe54:b09c]) by gaoxing.magnetkern.de (Postfix) with ESMTPSA id 4BE937368D; Sat, 04 Jan 2025 00:23:19 +0100 (CET) Date: Sat, 4 Jan 2025 00:22:03 +0100 From: Jan Behrens To: Adrian Klaver Cc: "David G. Johnston" , "pgsql-general@lists.postgresql.org" Subject: Re: search_path for PL/pgSQL functions partially cached? Message-Id: <20250104002203.2aed83d48d795ce6fbbd3b61@magnetkern.de> In-Reply-To: <14e035fb-ab35-4a73-a637-ad0180067b07@aklaver.com> References: <20241227205025.1d059f72c7c08d23c9648c26@magnetkern.de> <20241228004009.267f21b78394c934f27f9974@magnetkern.de> <20250103135332.7910a008714abaa04d32e5e2@magnetkern.de> <20250103174849.f071d9c6942f76a9b812157c@magnetkern.de> <20250103223312.dde69ae482776e4f1b0c2258@magnetkern.de> <14e035fb-ab35-4a73-a637-ad0180067b07@aklaver.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; amd64-portbld-freebsd14.1) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 3 Jan 2025 13:56:02 -0800 Adrian Klaver wrote: > At this point I am lost as to what the overall goal of this is. > > Can you provide a 10000 ft view if what it is you are trying to achieve? Sure! I would like to create a component (e.g. a PostgreSQL extension) that provides a function which processes some complex data, without making any requirements regarding where the data is stored. To pass this data to the function, I could use arrays of composite types, but that seems to be very bulky. Another option would be to use cursors, but that didn't turn out to work very smooth either. Instead, I plan to expect the function to receive a query string that will get the data that is being processed by the function. That query string should be allowed to refer to tables in the search_path at the caller's side. Therefore, I cannot use the "SET search_path FROM CURRENT" in my "CREATE FUNCTION" statement, because it would overwrite the current search_path on each call of the function. Thus my idea is to do this (simplified): CREATE FUNCTION "some_function" ("query_p" TEXT) RETURNS "some_type" -------------------------------------------------------------------- -- I cannot use SET search_path FROM CURRENT here, because "query_p" -- shall refer to tables in the search_path of the caller. -------------------------------------------------------------------- LANGUAGE plpgsql AS $$ DECLARE "old_search_path" TEXT; ---------------------------------------------------------------- -- I have to fully qualify types in the DECLARE section. ---------------------------------------------------------------- "some_variable" "some_schema"."some_type"; BEGIN SELECT current_setting('search_path') INTO "old_search_path"; PERFORM set_config( 'search_path', 'some_schema, pg_temp, ' || "old_search_path", TRUE ); ---------------------------------------------------------------- -- Do I have to fully qualify types and operators from -- "myschema" here? Or is it safe to not fully qualify them? ---------------------------------------------------------------- END; $$; That is my overall idea. My problem is that I'm confused about WHEN EXACTLY I have to qualify tables/types, etc. It is very hard to understand from reading (just) the documentation. Kind Regards, Jan Behrens