pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Sargent <robjsargent@gmail.com>
To: Adrian Klaver <adrian.klaver@aklaver.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: schema agnostic functions in language sql
Date: Fri, 15 May 2020 16:53:34 -0600
Message-ID: <92aa43c7-6b96-ab7f-ddde-61346f957801@gmail.com> (raw)
In-Reply-To: <a15a707a-1c33-8d23-6133-ff1466234700@aklaver.com>
References: <db508d6f-7e78-e57d-85f1-515353c66e43@gmail.com>
	<a15a707a-1c33-8d23-6133-ff1466234700@aklaver.com>



On 5/15/20 4:43 PM, Adrian Klaver wrote:
> On 5/15/20 3:26 PM, Rob Sargent wrote:
>> I'm using postgres 12.2, with multiple identical schema per database 
>> (each with a matching role).  I can write public plpgsql functions 
>> without using a schema identifier and let the runtime search_path 
>> find the correct schema-dependent table.  The same does not appear to 
>> be true for plain sql functions.  The 'parser'? does not recognize 
>> the tables (sans schema qualifier):
>>
>>     ERROR:  relation "<tablename>" does not exist.
>
> You probably need to show example code, because I don't see this:
>
> show search_path ;
>                            search_path
> ------------------------------------------------------------------
>  public,accounting,history,main,utility,timeclock,table_templates
>
> \d utility.login_info
>                                Table "utility.login_info"
>    Column    |              Type              | Collation | Nullable | 
>    Default
> -------------+--------------------------------+-----------+----------+------------------ 
>
>  user_name   | character varying              | | not null |
>  user_pwd    | character varying              | | not null |
>  user_role   | character varying              | |          |
>  ts_insert   | timestamp(0) without time zone | |          | now()
>  ts_update   | timestamp(0) without time zone | |          |
>  user_update | character varying(20)          | |          |
>  user_insert | character varying(20)          | |          | 
> "session_user"()
>
>
> CREATE FUNCTION getli(varchar) RETURNS login_info AS $$
>     SELECT * FROM login_info WHERE user_name = $1;
> $$ LANGUAGE SQL;
>
> select * from getli('aklaver');
>  user_name | user_pwd | user_role |      ts_insert      | 
> ts_update      | user_update | user_insert
> -----------+----------+-----------+---------------------+---------------------+-------------+------------- 
>
>  aklaver   | ranger   |           | 12/29/2012 12:23:17 | 05/15/2020 
> 15:41:14 |             | postgres
> (1 row)
>
Isn't "utility" in your path above?
>
>>
>> I would rather not have to duplicate these across multiple schema - 
>> I'll use plpgsql instead unless I've overlooked some other avenue.
>>
>> I've found that I can create the function, in public, if I set the 
>> search_path containing one schema (of course) and then successfully 
>> access the function after resetting the search path to use a second 
>> schema.  My "build the world" scripting has so far avoided needing to 
>> know/use any specific role.  Another pipe dream vaporized?
>>
>> Thanks,
>> rjs
>>
>>
>
>






view thread (15+ messages)  latest in thread

Message-ID: <92aa43c7-6b96-ab7f-ddde-61346f957801@gmail.com>
Permalink:  ../92aa43c7-6b96-ab7f-ddde-61346f957801@gmail.com/
Also on:    postgresql.org/message-id/92aa43c7-6b96-ab7f-ddde-61346f957801@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: robjsargent@gmail.com, adrian.klaver@aklaver.com
  Subject: Re: schema agnostic functions in language sql
  In-Reply-To: <92aa43c7-6b96-ab7f-ddde-61346f957801@gmail.com>
  References: <db508d6f-7e78-e57d-85f1-515353c66e43@gmail.com> <a15a707a-1c33-8d23-6133-ff1466234700@aklaver.com> <92aa43c7-6b96-ab7f-ddde-61346f957801@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox