Re: change database - Mailing list pgsql-general

From Jeff Davis
Subject Re: change database
Date
Msg-id 1247681637.5902.70.camel@monkey-cat.sm.truviso.com
Whole thread Raw
In response to change database  (Florian Chis <florian.chis@gmail.com>)
List pgsql-general
On Wed, 2009-07-15 at 11:36 +0300, Florian Chis wrote:
> I'm working on a port from mysql to postgres. I have a function which
> connect's to the database, checks for database existance and creates
> it otherwise.
> The last thing it does it executes "use my_database" (mysql stuff).
> Now I'm trying to find something similar in postgres. I know that psql
> has \c but that dosen't help me with jdbc. I also know that the easy
> solution out of this is to close the connection and then open it again
> with /my_database in the URL but I want to avoid this.
>
> So what are my options?

In PostgreSQL, a "schema" is similar to a "database" in MySQL -- both
are effectively namespaces (logical separation). You can switch
namespaces (schemas) in postgresql without reconnecting by simple set
commands, like: SET search_path = my_new_schema, public;

In PostgreSQL, a "database" is more of a physical separation, and your
connection is tied to a particular database. This is probably not what
you want.

More information here:
http://www.postgresql.org/docs/8.4/static/sql-createschema.html
http://www.postgresql.org/docs/8.4/static/sql-createdatabase.html

Regards,
    Jeff Davis


pgsql-general by date:

Previous
From: John R Pierce
Date:
Subject: savepoints in 8.3.7 or whatever...
Next
From: Mike Toews
Date:
Subject: Re: PL/Python debugging - line numbers