schema name in the SQL statement.

View: New views
3 Messages — Rating Filter:   Alert me  

schema name in the SQL statement.

by Masis, Alexander (US SSA) :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

My db has one schema. In fact I deleted the default "public" and created
my own: "schema_1".
In my SQL query I have to explicitly specify schema name:
"select my_colomn from schema_1.table_name;"
Can't schema be specified as default value during connection, or can I
set the schema before I send the query?




--
Sent via pgsql-interfaces mailing list (pgsql-interfaces@...)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-interfaces

Re: schema name in the SQL statement.

by Alvaro Herrera-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Masis, Alexander (US SSA) wrote:
> My db has one schema. In fact I deleted the default "public" and created
> my own: "schema_1".
> In my SQL query I have to explicitly specify schema name:
> "select my_colomn from schema_1.table_name;"
> Can't schema be specified as default value during connection, or can I
> set the schema before I send the query?

You can change the database so that everybody connecting to it will use
that schema:
ALTER DATABASE your_db SET search_path = 'schema_1';

You can do that per-user, too:
ALTER DATABASE username SET search_path = 'schema_1';

You can also change it in the application, by sending
SET search_path TO 'schema_1';

There are other options too, but that should suffice.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

--
Sent via pgsql-interfaces mailing list (pgsql-interfaces@...)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-interfaces

Re: schema name in the SQL statement.

by Bosco Rama :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Masis, Alexander (US SSA) wrote:
> My db has one schema. In fact I deleted the default "public" and created
> my own: "schema_1".
> In my SQL query I have to explicitly specify schema name:
> "select my_colomn from schema_1.table_name;"
> Can't schema be specified as default value during connection, or can I
> set the schema before I send the query?

After the connection is established, set the search_path to be your
schema:
   "set search_path to schema_1;"

At that point you can use unqualified relation references again:
   "select my_colomn from table_name;"


Bosco.

--
Sent via pgsql-interfaces mailing list (pgsql-interfaces@...)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-interfaces