Re: PSQL = Yes ... JDBC = no ??

From: "Peter J(dot) Holzer" <hjp-pgsql(at)hjp(dot)at>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: PSQL = Yes ... JDBC = no ??
Date: 2023-09-04 06:15:34
Message-ID: 20230904061534.cwdot6mpaqbbdakx@hjp.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2023-09-03 20:19:44 -0400, Amn Ojee Uw wrote:
> I see now, any suggestions as work around in JDBC?

Implement the functionality in Java.

You could do it directly:

execute
SELECT 'CREATE DATABASE jme_test_database' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'jme_test_database')
read the result
for each row returned
execute it as SQL

But that would be silly.

Instead you would do it like this:

execute
SELECT datname FROM pg_database WHERE datname = 'jme_test_database'
read the result
if the result is empty:
execute
CREATE DATABASE jme_test_database'

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp(at)hjp(dot)at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Rowley 2023-09-04 09:01:14 Re: Question on Partition key
Previous Message Jethro Elmer Sanidad 2023-09-04 05:16:48 Re: [EXTERNAL] Oracle FDW version