Skip to content

Commit

Permalink
Fix getSchemas for 7.3 servers. 7.3 cannot extract an array element
Browse files Browse the repository at this point in the history
from an array that is returned by a function.  Instead coerce it to
text and pull it out with a regex.
  • Loading branch information
kjurka committed Apr 2, 2011
1 parent c934074 commit 1543ab1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2004-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v 1.44.2.5 2010/10/16 00:39:27 jurka Exp $
* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v 1.44.2.6 2010/12/22 16:54:18 jurka Exp $
*
*-------------------------------------------------------------------------
*/
Expand Down Expand Up @@ -2149,7 +2149,11 @@ public java.sql.ResultSet getSchemas() throws SQLException
// because they can't access any objects in them.
if (connection.haveMinimumServerVersion("7.3"))
{
sql = "SELECT nspname AS TABLE_SCHEM FROM pg_catalog.pg_namespace WHERE nspname <> 'pg_toast' AND (nspname !~ '^pg_temp_' OR nspname = (pg_catalog.current_schemas(true))[1]) AND (nspname !~ '^pg_toast_temp_' OR nspname = replace((pg_catalog.current_schemas(true))[1], 'pg_temp_', 'pg_toast_temp_')) ORDER BY TABLE_SCHEM";
String tempSchema = "substring(textin(array_out(pg_catalog.current_schemas(true))) from '{(pg_temp_[0-9]+),')";
if (connection.haveMinimumServerVersion("7.4")) {
tempSchema = "(pg_catalog.current_schemas(true))[1]";
}
sql = "SELECT nspname AS TABLE_SCHEM FROM pg_catalog.pg_namespace WHERE nspname <> 'pg_toast' AND (nspname !~ '^pg_temp_' OR nspname = " + tempSchema + ") AND (nspname !~ '^pg_toast_temp_' OR nspname = replace(" + tempSchema + ", 'pg_temp_', 'pg_toast_temp_')) ORDER BY TABLE_SCHEM";
}
else
{
Expand Down

0 comments on commit 1543ab1

Please sign in to comment.