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 1tRGuo-008Q0Q-I4 for pgsql-general@arkaria.postgresql.org; Fri, 27 Dec 2024 20:26:35 +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 1tRGun-00CnyD-8L for pgsql-general@arkaria.postgresql.org; Fri, 27 Dec 2024 20:26:32 +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 1tRGum-00Cny3-Pg for pgsql-general@lists.postgresql.org; Fri, 27 Dec 2024 20:26:32 +0000 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tRGuk-000qo0-34 for pgsql-general@lists.postgresql.org; Fri, 27 Dec 2024 20:26:31 +0000 Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3ebadbb14dcso3190585b6e.3 for ; Fri, 27 Dec 2024 12:26:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735331190; x=1735935990; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=f/diJYKJIdnhKo7hq+2+JQug0B98+VqG7tm5ph44TkU=; b=VWxzLYHp0g3woxkblSCKzHhub44FKk4G8M/KnkOD8fafmdTLBVG8IWs95u1Q8CaULZ CaYUTSiA4QmeVuTc1fK/VSPJcfrBxl9OoUbmwHjL6drTg0bQVQupbrC1+pF/4YBJhi0h WE0KhqoQpbREB98Rf0WQi6WoS8kgQYvZmDCKCTRi85AMEgVUezBcPWb6vEaYoKs42ya8 ZAvW5GiC/SidTredUYZ1se1nkA3nFz86/CqVMCkGFodpMsilDrPUcCYhZLUd1Yb0RtGn 52g0MQ2GdKQsdVFoiRhjjrC4S/ILtBq8FFbuSdKRci9+rhnoH/1xLQoA9FuKkh7/k5R3 kxCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735331190; x=1735935990; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=f/diJYKJIdnhKo7hq+2+JQug0B98+VqG7tm5ph44TkU=; b=AOtMDTR8WXGvlDI0mYGwrZeE/FTgWh9HGiNsjEBj4TlfNR2SEsUqY9PyUkeekhGHqw HYwryjnb1nYC5tGHMRwOIaZD1K0c0rFF968BnhjGz3AooMNCoLYbGZEA5Utyfi4MXyKv rwvf2G24tlIxHGHIJ4C5yhWD1/WX+7I9kp+JrDstZhvjE579+UN6/KaWAswOwA0Yjf4U H8rjDyoVinxeJL4e1zDkam6is2sFRiiNY9bdJs1zTDN3TMQzZnU7AY2MAxhwra9WDqd9 GnzvXWnNRLz9HAyOgzQa0Ronv8I72ZaSCmVhg9mcp5u+gGuZwwHXLnihI+ibuBYqS0ch mEuw== X-Gm-Message-State: AOJu0Yz0ZDMx8MTVedXOC59o5yW6CQ+cuTJ66YLLrMtKZeUs0ZDnAHnG 3Yt9+7ggPqb2i+yZhwI6/L+9Yqp4g0fLFxIaEoN54v9GgmDoVGGojw+ybk8Ph6vkFr5ZP0cZMeJ aCQZ9uP7Ocx/pRrg3xKoD4x5rEtPicA== X-Gm-Gg: ASbGncuMcAUE7RK/ISPSU0LrXgSbaPbXlvcdD53nO9t8wc+5tWj1IAXETXwjo16SBHK f2MVp5y2DjaoN/wgvmP4nPsEL5ugzJ0COXzOXZQ== X-Google-Smtp-Source: AGHT+IEW2WtUMU1SA9BWepaQjwn8a7T0XIW4zoftYv4uoifEuCuObg77xU56CnsIrD4gZoBa3dS30AACJK/PoKh0O3k= X-Received: by 2002:a05:6808:1597:b0:3eb:4076:865e with SMTP id 5614622812f47-3ed803566femr16055092b6e.0.1735331188709; Fri, 27 Dec 2024 12:26:28 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a8a:29a:0:b0:577:9519:f64a with HTTP; Fri, 27 Dec 2024 12:26:28 -0800 (PST) In-Reply-To: <20241227205025.1d059f72c7c08d23c9648c26@magnetkern.de> References: <20241227205025.1d059f72c7c08d23c9648c26@magnetkern.de> From: "David G. Johnston" Date: Fri, 27 Dec 2024 13:26:28 -0700 Message-ID: Subject: Re: search_path for PL/pgSQL functions partially cached? To: Jan Behrens Cc: "pgsql-general@lists.postgresql.org" Content-Type: multipart/alternative; boundary="000000000000122550062a464778" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000122550062a464778 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Friday, December 27, 2024, Jan Behrens wrote: > > > It seems that it matters *both* how the search_path was set during the > *first* invocation of the function within a session *and* how it is set > during the actual call of the function. So even if there are just two > schemas involved, there are 4 possible outcomes for the "run" function's > result ('2.4', '2', '5', and '5.4'). To me, this behavior seems to be > somewhat dangerous. Maybe it is even considered a bug? It is what it is - and if one is not careful one can end up writing hard-to-understand and possibly buggy code due to the various execution environments and caches involved. I=E2=80=99ve never really understood why =E2=80=9C%TYPE=E2=80=99 exists=E2= =80=A6 > Or is it documented somewhere? https://www.postgresql.org/docs/current/plpgsql-implementation.html#PLPGSQL= -PLAN-CACHING Can someone explain to me what's going on, and what is the best practice to > deal with it? Is there a way to avoid fully qualifying every type and > expression? Which parts do I have to qualify or is this something that > could be fixed in a future version of PostgreSQL? > Add qualification or attach a =E2=80=9Cset search_path=E2=80=9D clause to = =E2=80=9Ccreate function=E2=80=9D. Code stored in the server should not rely on the sessio= n search_path. David J. --000000000000122550062a464778 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Friday, December 27, 2024, Jan Behrens <jbe-mlist@magnetkern.de> wrote:

It seems that it matters *both* how the search_path was set during the *fir= st* invocation of the function within a session *and* how it is set during = the actual call of the function. So even if there are just two schemas invo= lved, there are 4 possible outcomes for the "run" function's = result ('2.4', '2', '5', and '5.4'). To me,= this behavior seems to be somewhat dangerous. Maybe it is even considered = a bug?

It is what it is - and if one is not= careful one can end up writing hard-to-understand and possibly buggy code = due to the various execution environments and caches involved.
I=E2=80=99ve never really understood why =E2=80=9C%TYPE=E2=80= =99 exists=E2=80=A6


=
Or is it documented somewhere?= =C2=A0


Can some= one explain to me what's going on, and what is the best practice to dea= l with it? Is there a way to avoid fully qualifying every type and expressi= on? Which parts do I have to qualify or is this something that could be fix= ed in a future version of PostgreSQL?

A= dd qualification or attach a =E2=80=9Cset search_path=E2=80=9D clause to = =E2=80=9Ccreate function=E2=80=9D.=C2=A0 Code stored in the server should n= ot rely on the session search_path.

David J.
=

--000000000000122550062a464778--