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 1tU85V-00EM5g-DF for pgsql-general@arkaria.postgresql.org; Sat, 04 Jan 2025 17:37:26 +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 1tU85T-00C4by-0q for pgsql-general@arkaria.postgresql.org; Sat, 04 Jan 2025 17:37:22 +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 1tU85R-00C4bp-Ib for pgsql-general@lists.postgresql.org; Sat, 04 Jan 2025 17:37:22 +0000 Received: from fhigh-a8-smtp.messagingengine.com ([103.168.172.159]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tU85O-002549-1b for pgsql-general@lists.postgresql.org; Sat, 04 Jan 2025 17:37:19 +0000 Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id 5AB7211400FC; Sat, 4 Jan 2025 12:37:16 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Sat, 04 Jan 2025 12:37:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1736012236; x=1736098636; bh=luqbtZKeCnjvaJDF+Mcnvlmi1NAlvXrNCCHHiVkknxY=; b= Buz8z4obFjTtcDCXymIMvC45bpwU0uDGGDdtTA2tMi4LT1akRm0T2CsVhxPNS5AW L8jREexjTbSYy/AbSmKoL1xTAwaoKEquGOmkTGHNs/4X7zoKp7lmbBWs/OMCHQBo z8p+qjFgm5aHcOj8fEscWKnhtg40bHKLK5s6mAcZvnXdRt1BlpszOvnluQ4v4iTD iWpB5PEPQmOsG7k/Bdk0yIrqEiZ9QPShWYs6uQ60xQfgjCTblqiQZI1uXLvq92Rv ZCcFViWkPa/T6MzYhcFTG+Brr75IjFxh2AFMSluTNUHjRwupLbh+QhltXOCuhrW/ EdQOBKitDxE2Fgc762Y/0Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1736012236; x= 1736098636; bh=luqbtZKeCnjvaJDF+Mcnvlmi1NAlvXrNCCHHiVkknxY=; b=f 6gwuDORcetGLJ+uR9UVqBqWuEZIPFOfzO2SOs22FufLgYsCFixNKd9dn6VpJeoG7 KtP/yOxRw2jK8xMpDmM9g945IjS4JbirrYCFrrqlPkC3Ww5w+sE557aSQrGjyilZ lUOfkVuAVvhltOPYGgXeaeODPyuLSD5Wij1SW5Hw34DY2ZCgYcG4sakpxnf95tx6 Rh/VX811HKBTUrJtwemLhyEZgG+DGbVxMcJ0MqQmx3bZHUMOJUROPmlazHQ/q7Gs HFq46xk+e7C+OTwlhoLI7te8A/IkJCEritOH17Pfwp6Y3J6/mnW32JQBsULCbr/i eK+WEsQtBaJuHv54NhlJA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudefiedguddtgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefkffggfgfuvfevfhfhjggtgfesthejredttddv jeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvg hrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeeuudefjeejgffgtddt geehgfekueevkeekieettedtkeffheeivdethfevffegueenucffohhmrghinhepphhosh htghhrvghsqhhlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhdpnh gspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepjhgsvgdq mhhlihhsthesmhgrghhnvghtkhgvrhhnrdguvgdprhgtphhtthhopegurghvihgurdhgrd hjohhhnhhsthhonhesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhgvghn vghrrghlsehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 4 Jan 2025 12:37:15 -0500 (EST) Message-ID: Date: Sat, 4 Jan 2025 09:37:14 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: search_path for PL/pgSQL functions partially cached? To: Jan Behrens Cc: "David G. Johnston" , "pgsql-general@lists.postgresql.org" 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> <20250104002203.2aed83d48d795ce6fbbd3b61@magnetkern.de> Content-Language: en-US From: Adrian Klaver In-Reply-To: <20250104002203.2aed83d48d795ce6fbbd3b61@magnetkern.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/3/25 15:22, Jan Behrens wrote: > 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. Is 'some_schema' a known item when installing? Once you have the search_path defined and assuming all the objects you want are in that path, then yes you can drop the schema qualification. > > 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. If you are doing this as an extension then I suspect you want the processes shown here: https://www.postgresql.org/docs/17/extend-extensions.html#EXTEND-EXTENSIONS-RELOCATION > > Kind Regards, > Jan Behrens -- Adrian Klaver adrian.klaver@aklaver.com