pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Prefixing schema name
4+ messages / 3 participants
[nested] [flat]

* Prefixing schema name
@ 2018-03-07 23:05  Tiffany Thang <tiffanythang@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Tiffany Thang @ 2018-03-07 23:05 UTC (permalink / raw)
  To: pgsql-general

Hi,
Would it be possible to create a table or index in a schema without
prefixing the schema name? I find it a hassle to keep specifying the schema
name when I create an object or performing DMLs in a schema. The
search_path configuration works only for queries.

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);

Thanks.

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Prefixing schema name
@ 2018-03-07 23:13  David G. Johnston <david.g.johnston@gmail.com>
  parent: Tiffany Thang <tiffanythang@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: David G. Johnston @ 2018-03-07 23:13 UTC (permalink / raw)
  To: Tiffany Thang <tiffanythang@gmail.com>; +Cc: pgsql-general

On Wed, Mar 7, 2018 at 4:05 PM, Tiffany Thang <tiffanythang@gmail.com>
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)"


> 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.
​​

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Prefixing schema name
@ 2018-03-08 07:02  Achilleas Mantzios <achill@matrix.gatewaynet.com>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Achilleas Mantzios @ 2018-03-08 07:02 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 08/03/2018 01:13, David G. Johnston wrote:
> On Wed, Mar 7, 2018 at 4:05 PM, Tiffany Thang <tiffanythang@gmail.com <mailto:tiffanythang@gmail.com>>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

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Prefixing schema name
@ 2018-03-08 21:34  Tiffany Thang <tiffanythang@gmail.com>
  parent: Achilleas Mantzios <achill@matrix.gatewaynet.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Tiffany Thang @ 2018-03-08 21:34 UTC (permalink / raw)
  To: Achilleas Mantzios <achill@matrix.gatewaynet.com>; +Cc: pgsql-general@lists.postgresql.org

Thanks David and Achilleas. This is no longer an issue. The table
previously went to the public schema. I'm not sure what I did. Anyway,
without a prefix, it defaults to the current schema.

On Thu, Mar 8, 2018 at 2:02 AM, Achilleas Mantzios <
achill@matrix.gatewaynet.com> wrote:

> 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....
>
> ​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
>
>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2018-03-08 21:34 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-03-07 23:05 Prefixing schema name Tiffany Thang <tiffanythang@gmail.com>
2018-03-07 23:13 ` David G. Johnston <david.g.johnston@gmail.com>
2018-03-08 07:02   ` Achilleas Mantzios <achill@matrix.gatewaynet.com>
2018-03-08 21:34     ` Tiffany Thang <tiffanythang@gmail.com>

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