Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aHIf5-0001pN-VM for pgsql-sql@arkaria.postgresql.org; Thu, 07 Jan 2016 22:04:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aHIf5-0003yD-Cc for pgsql-sql@arkaria.postgresql.org; Thu, 07 Jan 2016 22:04:03 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aHIf2-0003wJ-UQ for pgsql-sql@postgresql.org; Thu, 07 Jan 2016 22:04:01 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aHIey-0004gh-Uk for pgsql-sql@postgresql.org; Thu, 07 Jan 2016 22:03:59 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 5707820600 for ; Thu, 7 Jan 2016 17:03:55 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute3.internal (MEProxy); Thu, 07 Jan 2016 17:03:55 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=aklaver.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=ukXWNBT1X8hXA9bCvgwbVR3JjEc=; b=CmkJLm nXw1e/qYDOdQ5HBKgtsP8cUMvdUhpHLLsS6atWE2eE9s77wClDf1qkM3Qx4dkVGl 2faZYFeMdBn97T9t6FcPtmlsdcfrM21etBEQunf5GLSpafxdoDJ/mfrA8oyiQm0D o7hEVdpcH74Pf6ZBjxY9BTjDKTNuK5NHCesw0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=ukXWNBT1X8hXA9b CvgwbVR3JjEc=; b=KySpltpULh+M7eg5T//2dCy11XiBKnjFYdXzxtjhZqug2Kc qkfkZ6kqtkg2eSl4CHY2+nlBNH/L7aWHJgjKZJ2PPMqlGUoKd3V4n6wVwP7GWdJk tlC9IP0tsb4QhBflwecHBCbPoiNBuiNE0SZWVvLVAkH2IsmPg1Gycwl41D18= X-Sasl-enc: vcchBwH4nvz7/CuCgnXkGkSvCd2BJJn7A7AuwaAwwJ+H 1452204234 Received: from [192.168.1.2] (65-102-182-223.tukw.qwest.net [65.102.182.223]) by mail.messagingengine.com (Postfix) with ESMTPA id 97555C016F9; Thu, 7 Jan 2016 17:03:54 -0500 (EST) Subject: Re: public synonym To: "michael@sqlexec.com" , Eugene Yin References: <358282890.1765953.1452197860946.JavaMail.yahoo.ref@mail.yahoo.com> <358282890.1765953.1452197860946.JavaMail.yahoo@mail.yahoo.com> <568ECA21.20702@sqlexec.com> Cc: "pgsql-sql@postgresql.org" From: Adrian Klaver Message-ID: <568EE09B.4050101@aklaver.com> Date: Thu, 7 Jan 2016 14:03:07 -0800 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: <568ECA21.20702@sqlexec.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On 01/07/2016 12:27 PM, michael@sqlexec.com wrote: > You can infer the context by first setting the search_path variable. > You can set it initially in your connection or do it for a database > context or even a role context > SET search_path = MASTER_USER, public, pg_catalog; > ALTER DATABASE whatever SET search_path = MASTER_USER, public, pg_catalog; > ALTER ROLE whoever SET search_path = MASTER_USER, public, pg_catalog; Just be aware that Postgres folds identifiers to lower case: test=# create schema MASTER_USER; CREATE SCHEMA test=# \dn List of schemas Name | Owner -------------+---------- master_user | postgres public | postgres test=# create table MASTER_USER.test_tbl(id int); CREATE TABLE test=# \d master_user.test_tbl Table "master_user.test_tbl" Column | Type | Modifiers --------+---------+----------- id | integer | UNLESS the tool you are using to create objects quotes the object name: test=# create schema "MASTER_USER"; CREATE SCHEMA test=# create table MASTER_USER.test_tbl(id int); ERROR: schema "master_user" does not exist test=# create table "MASTER_USER".test_tbl(id int); CREATE TABLE test=# \d "MASTER_USER".test_tbl Table "MASTER_USER.test_tbl" Column | Type | Modifiers --------+---------+----------- id | integer | More details at: http://www.postgresql.org/docs/9.4/static/sql-syntax-lexical.html 4.1.1. Identifiers and Key Words > > Then you can continue to let the tables be non-qualified. bye bye > synonyms! > > Regards > Michael >> Eugene Yin >> Thursday, January 7, 2016 3:17 PM >> PostgreSQL ver 9.4.5. Linux OS. >> Application: Web Based >> >> Platform: >> App Server (java) --> jdbc call --> Database Server (PostgreSQL) >> >> >> I do know that PostgreSQL does not support the public synonym.Now, for >> a user schema (let's call it MASTER_USER), if I coded in the stored >> function/procedure like the following, without using a public synonym >> to identify the table name: >> >> select user_name from user_info_table >> >> then access it from the Java (web app) sidevia the JDBC call to the >> database, will that work? >> >> OR, >> >> I must use the identifier inside the sql, such as: >> >> select user_name fromMASTER_USER.user_info_table? >> >> >> I come from the Oracle world, there I first create the public synonym >> for the table, then in the stored procedure I just directly reference >> the table with no need to identify the table with a schema name. Like >> to know how it work under the PostgreSQL. >> >> >> Thanks >> >> Eugene > -- Adrian Klaver adrian.klaver@aklaver.com -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql