Обсуждение: change database

Поиск
Список
Период
Сортировка

change database

От
Florian Chis
Дата:
Hi,

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?

With thanks,
Florian

Re: change database

От
Jeff Davis
Дата:
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


Re: change database

От
Bill Moran
Дата:
In response to Florian Chis <florian.chis@gmail.com>:
>
> 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.

Close the connection and reopen it.  There's no equivalent.

--
Bill Moran
http://www.potentialtech.com
http://people.collaborativefusion.com/~wmoran/

Re: change database

От
Florian Chis
Дата:
Since there is no other way, I'll close it then reopen it again.
Thank you for your time.

Regards,
Florian Chis


2009/7/15 Bill Moran <wmoran@potentialtech.com>
In response to Florian Chis <florian.chis@gmail.com>:
>
> 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.

Close the connection and reopen it.  There's no equivalent.

--
Bill Moran
http://www.potentialtech.com
http://people.collaborativefusion.com/~wmoran/

uuid-ossp for PostGres 8.4 running on Windows

От
Michael Gould
Дата:

Does anyone have a install or the proper files (not the source) to install the uuid-ossp contrib files for 8.4?  The one thing that I think that EnterpriseDB install is lacking in is the contrib modules that have been in the previous postgres version installation.  Is this something that is going to be added back into the EnterpriseDB installer?

At any rate my main concern now is to get the uuid-ossp install for 8.4 so that I can use 8.4 for our new development.

 

Best Regards


Michael Gould, Managing Partner
Intermodal Software Solutions, LLC
904.226.0978
904.592.5250 fax

Re: uuid-ossp for PostGres 8.4 running on Windows

От
Sachin Srivastava
Дата:
Hello Michael,

In the EnterpriseDB installer, uuid-ossp contrib module is available but not loaded/enabled by default. To enable uuid-ossp module simply run the uuid-ossp.sql file ("share\contrib\uuid-ossp.sql").

This is something that i did:
psql.exe -U postgres -d postgres -f share\contrib\uuid-ossp.sql

Then from psql i fired the below query and got results,
SELECT uuid_generate_v3(uuid_ns_url(), 'http://www.postgresql.org');

Hope it helps.



On 07/18/2009 08:00 PM, Michael Gould wrote:

Does anyone have a install or the proper files (not the source) to install the uuid-ossp contrib files for 8.4?  The one thing that I think that EnterpriseDB install is lacking in is the contrib modules that have been in the previous postgres version installation.  Is this something that is going to be added back into the EnterpriseDB installer?

At any rate my main concern now is to get the uuid-ossp install for 8.4 so that I can use 8.4 for our new development.

 

Best Regards


Michael Gould, Managing Partner
Intermodal Software Solutions, LLC
904.226.0978
904.592.5250 fax


-- 
Regards,
Sachin Srivastava
www.enterprisedb.com

Re: uuid-ossp for PostGres 8.4 running on Windows

От
Michael Gould
Дата:

Thanks, that worked perfectly.

Best Regards

Michael Gould

 

"Sachin Srivastava" <sachin.srivastava@enterprisedb.com> wrote:
 

Hello Michael,

In the EnterpriseDB installer, uuid-ossp contrib module is available but not loaded/enabled by default. To enable uuid-ossp module simply run the uuid-ossp.sql file ("share\contrib\uuid-ossp.sql").

This is something that i did:
psql.exe -U postgres -d postgres -f share\contrib\uuid-ossp.sql

Then from psql i fired the below query and got results,
SELECT uuid_generate_v3(uuid_ns_url(), 'http://www.postgresql.org');

Hope it helps.



On 07/18/2009 08:00 PM, Michael Gould wrote:

Does anyone have a install or the proper files (not the source) to install the uuid-ossp contrib files for 8.4?  The one thing that I think that EnterpriseDB install is lacking in is the contrib modules that have been in the previous postgres version installation.  Is this something that is going to be added back into the EnterpriseDB installer?

At any rate my main concern now is to get the uuid-ossp install for 8.4 so that I can use 8.4 for our new development.

 

Best Regards


Michael Gould, Managing Partner
Intermodal Software Solutions, LLC
904.226.0978
904.592.5250 fax


-- 
Regards,
Sachin Srivastava
www.enterprisedb.com