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 1jZkEC-0002AF-PU for pgsql-general@arkaria.postgresql.org; Fri, 15 May 2020 23:58:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jZkEB-0004us-ML for pgsql-general@arkaria.postgresql.org; Fri, 15 May 2020 23:58:55 +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 1jZkEB-0004tM-Cp for pgsql-general@lists.postgresql.org; Fri, 15 May 2020 23:58:55 +0000 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jZkE5-00026Y-3H for pgsql-general@lists.postgresql.org; Fri, 15 May 2020 23:58:54 +0000 Received: by mail-io1-xd42.google.com with SMTP id k6so4589258iob.3 for ; Fri, 15 May 2020 16:58:48 -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-transfer-encoding:content-language; bh=hZRUBvu8OTO3ZXX8GQdGlsY4Brg06zxFEb+DrtBeKyo=; b=KgEUaSwsctpyFy5RZUn3mv03Xr2scPnMKw3c1kYn5X/7qg854bcLlrIve5CmDZSBzx HyOoV6CKvUj5kCyeR4Qoz9SZmX8kNNZhQwxVLFkcMCOWHqDNHqEbmTDBXBMtvtx5P7+O b3FAOqnBg1g5WPxSBgLjeLKXYbpcl5S+Ijcg15ZR+TdcjXFC5FmKyfFSGfih0Oi4VP8P 83pt6lL59U0+3zu3FA2KxA+B8uvigWvF8y1jBLwo2nFTaquQoZLW3/Kjx/jFidGhl5+q qk6b9JqaqC3RB6oIvZWnbni0WArHszYoFHP4hoeX6GRgW0l7Hap3YxwTmqELgcPFS0a/ OF+w== 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-transfer-encoding :content-language; bh=hZRUBvu8OTO3ZXX8GQdGlsY4Brg06zxFEb+DrtBeKyo=; b=fjQoXjVfAZb4i9MkB+5VisZl+sSGIVAZV+EYFEt1/TtvvdKcOuNCph7uMa7w756W9O ArlfOOfiwEwU5UDJbSqnD2JbszrTE0oKgL2SbXSCJFsLWMw9uh3CjiGOwRWDvuaJASqy 6UUKYAdym0PpEbnTpr53VY03HHK2gvTVSvhiHv3GarTb6KzYduqHJV6LJ65CCQ+08Vqw 8JXKMSpF7MXg2DYygcHjpR4rKDIWk6pCZ6mzad1mTMU4UQcGVUiin8Eab5uIlWwIwO1c G9eBRRCtQJyBgXjBN9rKWX71tebnEM0G0h+HYYWumFo+Q2ttZwmf5G/blbNduSl9G/KM oGcQ== X-Gm-Message-State: AOAM531LICv4EPj0r4RpewaHeewx/HSjwa02vHIaP2AFiCVKEu1hRmPf SaeuUYkJu0TnfB5O24OgxGnvH9nQ X-Google-Smtp-Source: ABdhPJw12197kSRwLCO0/M5YGYwWIHLxoS5okIl+3yM7jqs1PbNOTzDZZ9JmAbEKBnGt4SVZYR5Wlg== X-Received: by 2002:a05:6602:2f0a:: with SMTP id q10mr3999414iow.134.1589587127790; Fri, 15 May 2020 16:58:47 -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 z24sm840821ioe.18.2020.05.15.16.58.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 15 May 2020 16:58:47 -0700 (PDT) Subject: Re: schema agnostic functions in language sql To: Tom Lane , "David G. Johnston" Cc: Adrian Klaver , "pgsql-generallists.postgresql.org" References: <92aa43c7-6b96-ab7f-ddde-61346f957801@gmail.com> <17840.1589586084@sss.pgh.pa.us> From: Rob Sargent Message-ID: <23231c96-2ddb-92dd-5539-08925bfcf314@gmail.com> Date: Fri, 15 May 2020 17:58:46 -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: <17840.1589586084@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 5/15/20 5:41 PM, Tom Lane wrote: > "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 Did my message with a sql and plgpsql versions not come through? I cannot create a plain sql function unless the search_path covers any table mentioned. Not the case when using plpgsql - no path needed. I'm ok(ish) with that, unless I've missed some detail. rjs