Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzR4t-0005u8-NS for pgsql-general@arkaria.postgresql.org; Thu, 28 Feb 2019 19:10:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gzR4s-0003nm-G4 for pgsql-general@arkaria.postgresql.org; Thu, 28 Feb 2019 19:10:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzR4s-0003kA-32 for pgsql-general@lists.postgresql.org; Thu, 28 Feb 2019 19:10:42 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzR4c-0002iu-7N for pgsql-general@postgresql.org; Thu, 28 Feb 2019 19:10:41 +0000 Received: by mail-pf1-x434.google.com with SMTP id a3so10152864pff.11 for ; Thu, 28 Feb 2019 11:10:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=Z+/nW0ADXpyD1zLb5JTuC/Z1jancTqnkeWGUC4qjFHk=; b=tNo+Xt/2Cq0iKMsH5K+AOScW0rvibdAlXgRRgjC/gzZa/KlnhoAH1AAvD1StDehTfK fqcMdNIboOtoo5U4FQrEScEonsc7mc8qE+sBTb8PfLtL8Z8C59pPhe/nIMDvVpGTA/Di KtXx6vcE8jm/8GBQrV3Y+6SP2XZCEZ7O8eyLqXxvr7mVf+GXLrhI49uOUb1UcmAUhQx7 ppFZOBR3ZwSdYjzGvdaOxxAXhw2PcQYYrCyGw5oJNx5OiLejeSZPXMhex4jcNYNMb3Ft XxKwB598MFUUEk2LLIbRQF5nzSZsgwDEbv4Tmq9W/ctIe4vkEqMToIa9SU7OtYEUiUIK aEVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=Z+/nW0ADXpyD1zLb5JTuC/Z1jancTqnkeWGUC4qjFHk=; b=DG6abmNDb/6F9uRdYybvc4zKhYJOmKWej0a2/Ebi/JbXgxFbratMlfIPfGEpA9aXfW JIT/smtf9+2xZsIAnFcZ+rzS1jWTjJarvFrhCJmRlxrOdt8/ZMcPI8CFB/xsIuix7dtF tA0STqYl9YH6jfdJHyFqZ2ZNM7hdf9HucyOANFDT/D/hOF4+cLPD976GQDRNjQ+1AI/T W07bHwhWaN3lP+TEFUS7HNRLgjktqF+1xw7KxRjBIRCKULB3m/C0JsNoKWjtSrr/OLtq ecv+1tlnIH0K9p4MyLha1Tiu7LKLGXN9OZqfPhHcSH/iNSuqL8fv24FhBCEMrZemi1wM jhcQ== X-Gm-Message-State: APjAAAWwUvodiyXbgeUca/Fr0Z5CU/Ii+Lwffmm1KoPyi4U6F2E/XZiM bhNXaZaIW9ALskByMxnQ0gEE/HC0 X-Google-Smtp-Source: APXvYqxd8LSUewfDAIPYEoUowZ7YKSA7uE5mn8pg3xuY+C15GI4PaQMaYQM5ubt9KPeOspP7eed3RA== X-Received: by 2002:a63:e03:: with SMTP id d3mr669443pgl.245.1551381023574; Thu, 28 Feb 2019 11:10:23 -0800 (PST) Received: from [10.104.134.14] ([155.100.47.6]) by smtp.gmail.com with ESMTPSA id v5sm21000071pfn.81.2019.02.28.11.10.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Feb 2019 11:10:22 -0800 (PST) To: "pgsql-general@postgresql.org" From: Rob Sargent Subject: specifying table in function args Message-ID: Date: Thu, 28 Feb 2019 12:10:21 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------018F9F23216D5D43878EC271" 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. --------------018F9F23216D5D43878EC271 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Using PG10.7, I have a database per investigator with one or more identical schemata per project.  So far I've gotten by defining public functions (as postgres) which reference tables /without/ schema reference.  Each project has a role which sets the search_path such that the project specific schema supplies the table definition at function call.  This seems to be working quite well. I've written a function which needs a specific record: create or replace function public.pvr(seg segment, plus float default 1.0) returns float as $$ declare   retval float; begin   select ((1.0*seg.events_equal)+seg.events_greater+plus)/(seg.events_less+seg.events_equal+seg.events_greater+plus) into retval;   return retval; end; $$ language plpgsql; but this fails in one of two ways:  either the create function call fails lacking a definition of "segment" or, if I create a public.segment table, create the function, set search_path to include a project's schema then drop public.segment fails because pvr() relies on it. This is all to avoid (the existing) pv() function which requires all events values as arguments (i.e. much typing). Is there a way through this or must I generate a function per schema in this case? It's easy enough to do, but has a certain odor to it. I suppose I could leave the public.segment table is place (revoke all inserts etc) then let the search_path take over. --------------018F9F23216D5D43878EC271 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Using PG10.7, I have a database per investigator with one or more identical schemata per project.  So far I've gotten by defining public functions (as postgres) which reference tables without schema reference.  Each project has a role which sets the search_path such that the project specific schema supplies the table definition at function call.  This seems to be working quite well.

I've written a function which needs a specific record:

create or replace function public.pvr(seg segment, plus float default 1.0)
returns float as $$
declare
  retval float;
begin
  select ((1.0*seg.events_equal)+seg.events_greater+plus)/(seg.events_less+seg.events_equal+seg.events_greater+plus) into retval;
  return retval;
end; 
$$ language plpgsql;

but this fails in one of two ways:  either the create function call fails lacking a definition of "segment" or, if I create a public.segment table, create the function, set search_path to include a project's schema then drop public.segment fails because pvr() relies on it.

This is all to avoid (the existing) pv() function which requires all events values as arguments (i.e. much typing). Is there a way through this or must I generate a function per schema in this case? It's easy enough to do, but has a certain odor to it. I suppose I could leave the public.segment table is place (revoke all inserts etc) then let the search_path take over.




--------------018F9F23216D5D43878EC271--