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 1tUE8U-00F3to-D8 for pgsql-general@arkaria.postgresql.org; Sun, 05 Jan 2025 00:04:54 +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 1tUE8T-00EOAA-FI for pgsql-general@arkaria.postgresql.org; Sun, 05 Jan 2025 00:04:53 +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 1tUE8T-00EO9x-3s for pgsql-general@lists.postgresql.org; Sun, 05 Jan 2025 00:04:52 +0000 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tUE8Q-0027et-39 for pgsql-general@lists.postgresql.org; Sun, 05 Jan 2025 00:04:51 +0000 Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3eba0f09c3aso4474350b6e.1 for ; Sat, 04 Jan 2025 16:04:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736035490; x=1736640290; 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=mG896WWUcvCW7bjOIbupGmdLYvr19sGCdHwORSfvS0w=; b=OP7ktQ71i4zoPbzA9TqdhFJe+FI11me4hLYyVCo+Mj0pZH4oYNtNgosUX2vsjFcfSh t1NEJW88SUMxVJakPcXFzm7cGPnUpDLyJQKI58mYoDpLpSCj47MOE9MpRkXZtB+DSPiq sR6hkDgdEWNdkU0RTBE4kcabeWEeS6I5lUSI/PwfSurC74hiMcJWuAy4ibNgyZBxnXCa 8GaHn8gsgh8XsPWRspYFtCuhD7kC6QJ9bbjmMyWUkzAPhTIOaBbByN9zAI/eJ9gQxTQk YNRpyoxboRZws/9afYxU0NRuS9kouNx+bStRwHgl6FbypQL0uMHH295bP6Kqh3sIc0kG 9FtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736035490; x=1736640290; 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=mG896WWUcvCW7bjOIbupGmdLYvr19sGCdHwORSfvS0w=; b=ZhRK8Hk6HR7FkYveDAvHCHLoERs7PnEtLe7QaOxS0thnlyCLaf3jugWo8hJ0SQ23jJ mDxZsfYhkanBmKuBUqMwFQ0TOhIRgn/0INF8Yy6XbEhA6IfBDZXVyhRyXPd8Ld3J2AyK C0sz/QBL3sI7RbqcrP/hazNwOFPWjM8c0n2WWX93Yg+y4CvxvPllcKUPWtKdYVqdBsa+ L2ChiMRsMWFvwCXqxFx5/9YwxdX4tpkNCMbMH7NU+NDpxCJ6V8JvVvgoHGMU8Hvo0Xid 6DS0gPeBDMHxLyviYfkexMiXb6ZSu0ZgDc7ZSzwd23zxYdSq+uV5hkGuqWpS/Ai0PTQp 9+uQ== X-Forwarded-Encrypted: i=1; AJvYcCXAcrnjRbjQxYibIQX+oxBG2u9QY1NjR8368L9FpEHYsk7C3TZb73Dxo/QvJrwqcGgT5f6jM+J3prreN262@lists.postgresql.org X-Gm-Message-State: AOJu0YwXpoLiDeODG7SXVZIBr5UuBCmA8F5u3xrWci+UCGXfJbYnjeOw HWiayyuU7k1Ak/wpVHmxa87+wD6pIQogbHZUjs8QvN/OcLt01Wp1DRGu7xM6/O2qQHHeujBv0HT bjhXYNaidj91nU5+U5Pe9+7ddq+c= X-Gm-Gg: ASbGncv6IMqYCGxEy/FJyj3tdo8f5DWQlg4B2ibgIy3G7DY10njM610N2gl3NJU9a0p NunmTK50oArLX+2l0RDplmnQ9SPO4pe06OlIbkg== X-Google-Smtp-Source: AGHT+IHaAp23N+7v4QJ6QU3bSlXb/VTplS8WTuDQvBkoglHXx3YYxxD95qpqMhFb4TPXs8auqSydsICSuO1/o7GTNxk= X-Received: by 2002:a05:6871:a113:b0:29e:76d1:db3b with SMTP id 586e51a60fabf-2a7fb002220mr33068784fac.5.1736035490073; Sat, 04 Jan 2025 16:04:50 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a8a:1872:0:b0:577:9519:f64a with HTTP; Sat, 4 Jan 2025 16:04:49 -0800 (PST) In-Reply-To: <20250105001249.cdca9dd84a3061c06f936ca7@magnetkern.de> 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> <20250105001249.cdca9dd84a3061c06f936ca7@magnetkern.de> From: "David G. Johnston" Date: Sat, 4 Jan 2025 17:04:49 -0700 Message-ID: Subject: Re: search_path for PL/pgSQL functions partially cached? To: Jan Behrens Cc: Adrian Klaver , Tom Lane , "pgsql-general@lists.postgresql.org" Content-Type: multipart/alternative; boundary="000000000000b41533062aea427c" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b41533062aea427c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Saturday, January 4, 2025, Jan Behrens wrote: > > > Even if > > DECLARE "variable" "tbl"."col"%TYPE; > > follows *after* the schema is set to "myschema" in the example above, I > still get differing results, depending on how the search_path was set > when the function was first called. > > I think this has to do with the fact that the overall structure and > probably types(?) are parsed first? > I concur that this dynamic doesn=E2=80=99t seem to be discussed. Namely th= at in the presence of nested blocks the parse phase resolves placeholders for all declared variables without executing any expressions in the body of the function; therefore all types will be resolved seeing the same search_path, namely that of the calling session or established using SET. Changing the search_path within an outer function body block will not affect declarations within an inner block. (I am not sure whether the for-loop cases are exceptional in this.) David J. --000000000000b41533062aea427c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Saturday, January 4, 2025, Jan Behrens <jbe-mlist@magnetkern.de> wrote:

Even if

DECLARE "variable" "tbl"."col"%TYPE;

follows *after* the schema is set to "myschema" in the example ab= ove, I
still get differing results, depending on how the search_path was set
when the function was first called.

I think this has to do with the fact that the overall structure and
probably types(?) are parsed first?

I concur that this dynamic doesn=E2=80=99t= seem to be discussed.=C2=A0 Namely that in the presence of nested blocks t= he parse phase resolves placeholders for all declared variables without exe= cuting any expressions in the body of the function; therefore all types wil= l be resolved seeing the same search_path, namely that of the calling sessi= on or established using SET.=C2=A0 Changing the search_path within an outer= function body block will not affect declarations within an inner block. (I= am not sure whether the for-loop cases are exceptional in this.)

David J.

--000000000000b41533062aea427c--