[libpostgresql-jdbc-java] 05/22: Add the partial index constraint to the FILTER_CONDITION column returned by DatabaseMetaData.getIndexInfo.

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:20:52 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to tag REL8_4_702
in repository libpostgresql-jdbc-java.

commit df9c12a32c9af8e9bd756ec4f04d76772508f0c1
Author: Kris Jurka <books at ejurka.com>
Date:   Fri Dec 4 21:22:02 2009 +0000

    Add the partial index constraint to the FILTER_CONDITION column
    returned by DatabaseMetaData.getIndexInfo.
    
    Mark Kirkwood
---
 .../jdbc2/AbstractJdbc2DatabaseMetaData.java       | 23 +++++++++++++++++-----
 .../test/jdbc2/DatabaseMetaDataTest.java           | 21 +++++++++++++++++++-
 2 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java b/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
index 9f4a0ed..8af40e9 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2004-2008, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v 1.51 2009/03/12 03:59:50 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v 1.51.2.1 2009/12/04 19:48:01 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -3840,7 +3840,7 @@ public abstract class AbstractJdbc2DatabaseMetaData
 
         if( connection.haveMinimumServerVersion("7.4"))
         {
-            sql += " CASE WHEN i.indexprs IS NULL THEN a.attname ELSE pg_get_indexdef(ci.oid,a.attnum,false) END AS COLUMN_NAME, ";
+            sql += " CASE WHEN i.indexprs IS NULL THEN a.attname ELSE pg_catalog.pg_get_indexdef(ci.oid,a.attnum,false) END AS COLUMN_NAME, ";
         }
         else
         {
@@ -3850,9 +3850,22 @@ public abstract class AbstractJdbc2DatabaseMetaData
 
         sql += " NULL AS ASC_OR_DESC, " +
                      " ci.reltuples AS CARDINALITY, " +
-                     " ci.relpages AS PAGES, " +
-                     " NULL AS FILTER_CONDITION " +
-                     from +
+                     " ci.relpages AS PAGES, ";
+
+        if( connection.haveMinimumServerVersion("7.3"))
+        {
+            sql += " pg_catalog.pg_get_expr(i.indpred, i.indrelid) AS FILTER_CONDITION ";
+        }
+	else if( connection.haveMinimumServerVersion("7.2"))
+        {
+            sql += " pg_get_expr(i.indpred, i.indrelid) AS FILTER_CONDITION ";
+        }
+        else
+        {
+            sql += " NULL AS FILTER_CONDITION ";
+        }
+
+        sql += from +
                      " WHERE ct.oid=i.indrelid AND ci.oid=i.indexrelid AND a.attrelid=ci.oid AND ci.relam=am.oid " +
                      where +
                      " AND ct.relname = '" + escapeQuotes(tableName) + "' ";
diff --git a/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java b/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java
index b405ac6..7e96add 100644
--- a/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java
+++ b/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2004-2008, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java,v 1.43 2008/04/15 05:22:14 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java,v 1.44 2008/11/07 09:11:37 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -447,6 +447,25 @@ public class DatabaseMetaDataTest extends TestCase
         rs.close();
     }
 
+    public void testPartialIndexInfo() throws SQLException
+    {
+        Statement stmt = con.createStatement();
+        stmt.execute("create index idx_p_name_id on testmetadata (name) where id > 5");
+        stmt.close();
+
+        DatabaseMetaData dbmd = con.getMetaData();
+        ResultSet rs = dbmd.getIndexInfo(null, null, "testmetadata", false, false);
+
+        assertTrue(rs.next());
+        assertEquals("idx_p_name_id", rs.getString("INDEX_NAME"));
+        assertEquals(1, rs.getInt("ORDINAL_POSITION"));
+        assertEquals("name", rs.getString("COLUMN_NAME"));
+        assertEquals("(id > 5)", rs.getString("FILTER_CONDITION"));
+        assertTrue(rs.getBoolean("NON_UNIQUE"));
+
+        rs.close();
+    }
+
     public void testTableTypes() throws SQLException
     {
         // At the moment just test that no exceptions are thrown KJ

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git



More information about the pkg-java-commits mailing list