Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1etpaw-0004Dj-8u for pgsql-general@arkaria.postgresql.org; Thu, 08 Mar 2018 07:04:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1etpav-0001Za-6R for pgsql-general@arkaria.postgresql.org; Thu, 08 Mar 2018 07:04:05 +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.89) (envelope-from ) id 1etpZb-0002NA-SH for pgsql-general@lists.postgresql.org; Thu, 08 Mar 2018 07:02:44 +0000 Received: from host3.dynacom.ondsl.gr ([62.103.35.211] helo=smadev.internal.net) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1etpZW-00063S-TB for pgsql-general@lists.postgresql.org; Thu, 08 Mar 2018 07:02:42 +0000 Received: from smadev.internal.net (smadev [10.9.200.131]) by smadev.internal.net (8.15.2/8.15.2) with ESMTP id w2872UoG096753 for ; Thu, 8 Mar 2018 09:02:31 +0200 (EET) (envelope-from achill@matrix.gatewaynet.com) Subject: Re: Prefixing schema name To: pgsql-general@lists.postgresql.org References: From: Achilleas Mantzios Message-ID: Date: Thu, 8 Mar 2018 09:02:30 +0200 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------A53874140E39C3B51D3B32F6" 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. --------------A53874140E39C3B51D3B32F6 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 08/03/2018 01:13, David G. Johnston wrote: > On Wed, Mar 7, 2018 at 4:05 PM, Tiffany Thang >wrote: > > ​ > The search_path configuration works only for queries. > > > ​Um.... > > ​https://www.postgresql.org/docs/10/static/sql-createschema.html > > "​A CREATE command specifying an unqualified object name creates the object in the current schema (the one at the front of the search path, which can be determined with the function current_schema)" > In pg_dump relies heavily on search_path for all CREATE statements. > > For example: > Is there a way to run the create/insert statements below without prefixing the schema name, user1?​ > > > As the user, user1: > Create table user1.table1 (id int); > Insert into user1.table1 values (1); > > > ​Just omitting "user1" and seeing what happens would be informative.  You should find it does exactly what you think - namely because the default search_path will cause "user1" to appear first. > > Insert is more similar to Select than it is to Create - the object being inserted into must already exist > > David J. > ​​ -- Achilleas Mantzios IT DEV Lead IT DEPT Dynacom Tankers Mgmt --------------A53874140E39C3B51D3B32F6 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
On 08/03/2018 01:13, David G. Johnston wrote:
On Wed, Mar 7, 2018 at 4:05 PM, Tiffany Thang <tiffanythang@gmail.com> wrote:
​
The search_path configuration works only for queries.

​Um....


"​A CREATE command specifying an unqualified object name creates the object in the current schema (the one at the front of the search path, which can be determined with the function current_schema)"


In pg_dump relies heavily on search_path for all CREATE statements.


For example:
Is there a way to run the create/insert statements below without prefixing the schema name, user1?​

As the user, user1:
Create table user1.table1 (id int);
Insert into user1.table1 values (1);

​Just omitting "user1" and seeing what happens would be informative.  You should find it does exactly what you think - namely because the default search_path will cause "user1" to appear first.

Insert is more similar to Select than it is to Create - the object being inserted into must already exist

David J.
​​


-- 
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt
--------------A53874140E39C3B51D3B32F6--