Hello!
This issue really puzzles me beyond intrigue.
Why would this schema:
SELECT 'CREATE DATABASE jme_test_database' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'jme_test_database')\gexec
work when entered at the psql prompt, but not when passed as a parameter in a JDBC method?
The bellow snip demonstrates the the creation of a String object with same character string used in the PSQL#.
//CREATE DATABASE IF NOT EXISTS
//~~~~~~~~~~~~~~~~~~
var s = new myString(SELECT 'CREATE DATABASE jme_test_database' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'jme_test_database')\gexec);
stmt.executeUpdate(s.toString());
However, this time PostgreSQL-15 complains with an error message saying :
Exception in thread "main" org.postgresql.util.PSQLException: ERROR: syntax error at or near "\"
Position: 122
For better clarification, I'd like to show the code to create the schema inside Java/JDBC.
---- snip ----
*/
...
var sv = myString();
...
public final myString getCreateDatabase(myString s){
this.sv.setData("SELECT 'CREATE DATABASE ");
this.sv.append(s.toString());
this.sv.append("\'");
this.sv.append("WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = ");
this.sv.append("\'");
this.sv.append(s.toString());
this.sv.append("\'");
this.sv.append(")\\gexec");
return sv;
}
Any help would be very much appreciated.
Thanks in advance.