Thread: query for schema existence and create schema in jdbc?

query for schema existence and create schema in jdbc?

From
"Hiller, Dean (Contractor)"
Date:

I need a way(and don’t care if it is not portable) to

 

1.       Query to see if a schema exists or not

2.       Create the schema if it doesn’t exist

3.       Drop and recreate the schema if it does exist

 

ALL through JDBC.  Is this possible?

Thanks,

Dean

This message and any attachments are intended only for the use of the addressee and
may contain information that is privileged and confidential. If the reader of the 
message is not the intended recipient or an authorized representative of the
intended recipient, you are hereby notified that any dissemination of this
communication is strictly prohibited. If you have received this communication in
error, please notify us immediately by e-mail and delete the message and any
attachments from your system.

Re: query for schema existence and create schema in jdbc?

From
"Hiller, Dean (Contractor)"
Date:

Sweet, never mind.

 

select * from pg_namespace; finds it. And of course create command creates it.

 

Dean

 

From: Hiller, Dean (Contractor)
Sent: Friday, January 21, 2011 7:15 AM
To: 'pgsql-jdbc@postgresql.org'
Subject: query for schema existence and create schema in jdbc?

 

I need a way(and don’t care if it is not portable) to

 

1.       Query to see if a schema exists or not

2.       Create the schema if it doesn’t exist

3.       Drop and recreate the schema if it does exist

 

ALL through JDBC.  Is this possible?

Thanks,

Dean

This message and any attachments are intended only for the use of the addressee and
may contain information that is privileged and confidential. If the reader of the 
message is not the intended recipient or an authorized representative of the
intended recipient, you are hereby notified that any dissemination of this
communication is strictly prohibited. If you have received this communication in
error, please notify us immediately by e-mail and delete the message and any
attachments from your system.

Re: query for schema existence and create schema in jdbc?

From
Samuel Gendler
Date:


On Fri, Jan 21, 2011 at 6:14 AM, Hiller, Dean (Contractor) <dean.hiller@broadridge.com> wrote:

I need a way(and don’t care if it is not portable) to

 

1.       Query to see if a schema exists or not

2.       Create the schema if it doesn’t exist

3.       Drop and recreate the schema if it does exist

 

ALL through JDBC.  Is this possible?



run this query, which returns a boolean:

select exists (select * from pg_catalog.pg_namespace where nspname = 'new_schema');

then either execute 'create schema new_schema;' or 'drop schema new_schema cascade; create schema new_schema;'