Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jZjeP-0001Im-Tf for pgsql-general@arkaria.postgresql.org; Fri, 15 May 2020 23:21:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jZjeO-0008C3-QU for pgsql-general@arkaria.postgresql.org; Fri, 15 May 2020 23:21:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jZjeO-0008Bv-HF for pgsql-general@lists.postgresql.org; Fri, 15 May 2020 23:21:56 +0000 Received: from mail-io1-xd43.google.com ([2607:f8b0:4864:20::d43]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jZjeM-0001eL-Gl for pgsql-general@lists.postgresql.org; Fri, 15 May 2020 23:21:56 +0000 Received: by mail-io1-xd43.google.com with SMTP id k18so4561316ion.0 for ; Fri, 15 May 2020 16:21:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=dsgTd1/AYX8Q+OZs3V9yqcgupdbr/K2yg0LWz4Wva0Q=; b=t2fWQ+sx/PxVmWdExNCISnox7TfOrMF8GeMC27dfDJw4cvdy2FEV3B3dXNbqW5nNv5 sVrxe8Wl8ybiYPP9JE9D02YxKTE59CWejvIs5EXIh0Ydbdryk1V9MUbupnN/z6LX1ovE Hwo6NBuC1z6OtS1eXwCQ+905UdSq7U8Io67xcerNP0Ow7A69RuTw6ger8b9/W1W4GtvC MuKxLenUHZtUrcxQOMan8l49rVzTLp2jeUo3jUReaGJEbdXZqs62k16I5BM3wAZfwsq+ OtAr4SGyvAjKxzhtYwVaPd6vka7JMXumUkulOLMAw8eWp8liisCBN4HZd9iwTrtVL7gF kJeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=dsgTd1/AYX8Q+OZs3V9yqcgupdbr/K2yg0LWz4Wva0Q=; b=SRterfmcebJS5gjxrMA20h6Mx8yRXlscC45PiiXGrgIy1boFpye/8T8M+0hpI6lq01 vFQtcLmeR9kwIhk+V8w15PaVKl7i8LD8YfNJmnqCJQx8IukSXCNkRkCAR/u07lf+uy2X 8Crp3enmYA3xLIzGGPKKW0ZDtileSShIUzNnbcL1H+i6/2kpAZWu5Xq+4mpTN1e9ahXw SqyHu/kyn2a1f+iVZzYxEHWflENAo+dbfdO4vAK2ZqDt3MzwakCs0iMYpQ8dOwZS7zXu y/D8H7onZhsmrRorJDA7kfQ1quBhx1WyKUXmE/Iny2ZOs+OQZ9fUCAOPGOTKry8pi4aR B5sg== X-Gm-Message-State: AOAM5315iWfLwupVZIKxpitGtfWW0bzMy2CRS5gANOOeBmFUoTchzIak E2mRLxX5y9tkSX8UzO1Aq1izPmcI X-Google-Smtp-Source: ABdhPJyyI57r5NBDsOFHuW89UpAwDQJA0Uos4byqzA/SQ19hjHBxsZHgnu+iRxeTMz2h0xJdtkL1Fw== X-Received: by 2002:a02:b816:: with SMTP id o22mr5263537jam.124.1589584912853; Fri, 15 May 2020 16:21:52 -0700 (PDT) Received: from ?IPv6:2601:681:5500:dde0:f120:2f2:891d:e9fe? ([2601:681:5500:dde0:f120:2f2:891d:e9fe]) by smtp.gmail.com with ESMTPSA id x11sm1458533ilm.64.2020.05.15.16.21.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 15 May 2020 16:21:52 -0700 (PDT) Subject: Re: schema agnostic functions in language sql To: "David G. Johnston" Cc: Adrian Klaver , "pgsql-generallists.postgresql.org" References: <92aa43c7-6b96-ab7f-ddde-61346f957801@gmail.com> From: Rob Sargent Message-ID: <46867210-4a1e-d066-2e63-1d3fe580a733@gmail.com> Date: Fri, 15 May 2020 17:21:51 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------108B795E09B38252EB7D21F4" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------108B795E09B38252EB7D21F4 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 5/15/20 5:16 PM, David G. Johnston wrote: > On Fri, May 15, 2020 at 4:07 PM Rob Sargent > wrote: > > I'm terribly sorry:  I needed to add that plpgsql works without any > knowledge of the schema, where as defining a plain sql functions does > not work without schema qualification. > > > You need to distinguish between "works" as in "compiles" and "works" > as in "executes". > > Yes, SQL and pl/pgsql have very different behaviors when it comes to > compilation and execution.  In particular SQL performs parsing earlier > (during creation - just like it does for views) and links the textual > query to its parse result earlier.  For pl/pgsql none of that happens > until the function is called.  Because of this pl/pgsql allows for > ambiguous sql text to exist and be concretely resolved during > execution while SQL does not. > Thank you for the confirmation.  I'll decide whether I move to plpgsql or dither with role/search_path in the db creation scripts. (Both forms, plpgsql and sql, "work" once given the correct context.) > David J. > --------------108B795E09B38252EB7D21F4 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

On 5/15/20 5:16 PM, David G. Johnston wrote:
On Fri, May 15, 2020 at 4:07 PM Rob Sargent <robjsargent@gmail.com> wrote:

I'm terribly sorry:  I needed to add that plpgsql works without any
knowledge of the schema, where as defining a plain sql functions does
not work without schema qualification.

You need to distinguish between "works" as in "compiles" and "works" as in "executes".

Yes, SQL and pl/pgsql have very different behaviors when it comes to compilation and execution.  In particular SQL performs parsing earlier (during creation - just like it does for views) and links the textual query to its parse result earlier.  For pl/pgsql none of that happens until the function is called.  Because of this pl/pgsql allows for ambiguous sql text to exist and be concretely resolved during execution while SQL does not.

Thank you for the confirmation.  I'll decide whether I move to plpgsql or dither with role/search_path in the db creation scripts.
(Both forms, plpgsql and sql, "work" once given the correct context.)
David J.


--------------108B795E09B38252EB7D21F4--