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 1jZjxQ-0001pI-8z for pgsql-general@arkaria.postgresql.org; Fri, 15 May 2020 23:41:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jZjxP-0003n9-5O for pgsql-general@arkaria.postgresql.org; Fri, 15 May 2020 23:41:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jZjxO-0003n2-Tb for pgsql-general@lists.postgresql.org; Fri, 15 May 2020 23:41:34 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jZjxI-0001xd-Fj for pgsql-general@lists.postgresql.org; Fri, 15 May 2020 23:41:33 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 04FNfOo0017841; Fri, 15 May 2020 19:41:24 -0400 From: Tom Lane To: "David G. Johnston" cc: Rob Sargent , Adrian Klaver , "pgsql-generallists.postgresql.org" Subject: Re: schema agnostic functions in language sql In-reply-to: References: <92aa43c7-6b96-ab7f-ddde-61346f957801@gmail.com> Comments: In-reply-to "David G. Johnston" message dated "Fri, 15 May 2020 16:16:54 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <17839.1589586084.1@sss.pgh.pa.us> Date: Fri, 15 May 2020 19:41:24 -0400 Message-ID: <17840.1589586084@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "David G. Johnston" writes: > 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. I don't think that's accurate. SQL functions are stored as plain text, just like any other non-C-coded function, and they are not parsed until execution. There are big differences from plpgsql of course. For one, it's possible for a SQL function to be "inlined" into the calling query, in which case parsing happens during planning of the calling query. But other than that, I'd expect the execution-time search path to determine how a SQL function behaves. Since Rob didn't provide any details, it's far from clear what's going wrong for him. regards, tom lane