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 1jZjD9-0000VK-P0 for pgsql-general@arkaria.postgresql.org; Fri, 15 May 2020 22:53:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jZjD7-00084S-D9 for pgsql-general@arkaria.postgresql.org; Fri, 15 May 2020 22:53:45 +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 1jZjD7-00084C-3f for pgsql-general@lists.postgresql.org; Fri, 15 May 2020 22:53:45 +0000 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jZjD0-0001J5-K7 for pgsql-general@lists.postgresql.org; Fri, 15 May 2020 22:53:44 +0000 Received: by mail-io1-xd44.google.com with SMTP id e18so4416214iog.9 for ; Fri, 15 May 2020 15:53:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=6hOMTi/NqQwA6VfJNu2WUkM6nCCfe66Yz019GhQ5Jkk=; b=MPrTrxS66VUQjzxf53MfE0m5lEhhUE83EaT0vax65eNoGQCiSPHh7am9SwPJIe6wSp zGZwQXfffGPHXJwUntw4MeAuwaTfR+/Ko+Rd8595qDU0x59aOJtdXeSnim/i9XLu8aun XISV2AybG/hLSWXtvQ61tbJ/6FFItmn3smcbZp1uLCPxjqsfdLAlqYXOolx5Ai5VxAAN lV912NU7knQIGQp7oCNSTBulL8n5nCwPOPiA8MCSHeE6gbjxQK2BaJYKvThYx4bjCtK5 vi6kRxg6S8JwYDxCDnKW7istsd8RtSXyz6n/Ww5EyTrNhNpyyCswi3Etz3WuKDISm6A9 QoYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=6hOMTi/NqQwA6VfJNu2WUkM6nCCfe66Yz019GhQ5Jkk=; b=OB9MVADrVKHw6nanTofkwsO6SGtDm6KZTaf0m8Cs/X9rctg0yoCD9wAn8c8uwoAynd AA12yGYDO7ZjonS0YqhFKMJt8d5iu4OinK+DkaFfre/fprK7BSigAVvHuTWO5V1JKtyQ a9eauuMZMufhttf6m93dtv52C26G+gYC8psU2J6Co4ZCVMUFjTzNbCyTpQcBnpu519Le ay520gqx3OurHW0VFU7i9e8SapQvQPkwVnfoEnHYEa7+xLVblfVD9jb6Rm0+irrtopYB 0XjR0agQIxrZ3q3rJ10OwJ3y2NX+8WieP+K4dBFDqnb744nds7rQsBEuTYsb7fCUnpUc CRgA== X-Gm-Message-State: AOAM532uKavZ8O35ysO9O409dSlagkVZHw1Lwa5rQahfB4zboefFC9hl Ksvb03OpdDFBQ7YT4+jeTT+O7oGu X-Google-Smtp-Source: ABdhPJy6iJgi3H2ORfVLdVWFIb4XPspfe+JeLjCdQhQ6Y7prBlrUYsalKUEizfCEvuMwzkIP+IKS4A== X-Received: by 2002:a05:6602:2ad3:: with SMTP id m19mr5040814iov.198.1589583216160; Fri, 15 May 2020 15:53:36 -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 f17sm1210928iol.26.2020.05.15.15.53.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 15 May 2020 15:53:35 -0700 (PDT) Subject: Re: schema agnostic functions in language sql To: Adrian Klaver , pgsql-general@lists.postgresql.org References: From: Rob Sargent Message-ID: <92aa43c7-6b96-ab7f-ddde-61346f957801@gmail.com> Date: Fri, 15 May 2020 16:53:34 -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: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 "" 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 >> >> > >