pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedDatabaseMetaData.getIndexInfo and function-based indexes
8+ messages / 3 participants
[nested] [flat]
* DatabaseMetaData.getIndexInfo and function-based indexes
@ 2005-02-18 22:55 peter royal <proyal@pace2020.com>
2005-02-19 04:07 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 8+ messages in thread
From: peter royal @ 2005-02-18 22:55 UTC (permalink / raw)
To: pgsql-jdbc
say i have an index:
create index my_index on my_Table (upper(my_field) );
it is possible to retrieve the fact that the field is upper(my_field)
via DMD.getIndexInfo() ?
With 7.4 (and the associated JDBC driver) the column name shows up as
pg_expression_1 (or something very close to that :)
... or is this something that is fixed in 8.0?
Thanks.
-pete
Attachments:
smime.p7s (application/pkcs7-signature, 2.3K) download
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: DatabaseMetaData.getIndexInfo and function-based indexes
2005-02-18 22:55 DatabaseMetaData.getIndexInfo and function-based indexes peter royal <proyal@pace2020.com>
@ 2005-02-19 04:07 ` Kris Jurka <books@ejurka.com>
2005-02-19 05:54 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 8+ messages in thread
From: Kris Jurka @ 2005-02-19 04:07 UTC (permalink / raw)
To: peter royal <proyal@pace2020.com>; +Cc: pgsql-jdbc
On Fri, 18 Feb 2005, peter royal wrote:
> create index my_index on my_Table (upper(my_field) );
>
> it is possible to retrieve the fact that the field is upper(my_field)
> via DMD.getIndexInfo() ?
>
> With 7.4 (and the associated JDBC driver) the column name shows up as
> pg_expression_1 (or something very close to that
This is what is actually stored in the pg_attribute table as the column
name for the index. Determining what the actual expression is would
involve decoding the pg_index.indexpr column with pg_get_expr, which could
be done, but then some manual parsing would need to be done to split this
into multiple columns for something like (upper(a), lower(b)). So the
driver can figure this information out, but doesn't presently.
Kris Jurka
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: DatabaseMetaData.getIndexInfo and function-based indexes
2005-02-18 22:55 DatabaseMetaData.getIndexInfo and function-based indexes peter royal <proyal@pace2020.com>
2005-02-19 04:07 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Kris Jurka <books@ejurka.com>
@ 2005-02-19 05:54 ` Tom Lane <tgl@sss.pgh.pa.us>
2005-02-19 14:02 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes peter royal <proyal@pace2020.com>
0 siblings, 1 reply; 8+ messages in thread
From: Tom Lane @ 2005-02-19 05:54 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: peter royal <proyal@pace2020.com>; pgsql-jdbc
Kris Jurka <books@ejurka.com> writes:
> This is what is actually stored in the pg_attribute table as the column
> name for the index. Determining what the actual expression is would
> involve decoding the pg_index.indexpr column with pg_get_expr, which could
> be done, but then some manual parsing would need to be done to split this
> into multiple columns for something like (upper(a), lower(b)). So the
> driver can figure this information out, but doesn't presently.
FYI, pg_get_indexdef makes that pretty simple in PG >= 7.4:
regression=# create table t1 (f1 text, f2 text);
CREATE TABLE
regression=# create index t1i on t1(upper(f1), lower(f2));
CREATE INDEX
regression=# select pg_get_indexdef('t1i'::regclass, 1, false);
pg_get_indexdef
-----------------
upper(f1)
(1 row)
regression=# select pg_get_indexdef('t1i'::regclass, 2, false);
pg_get_indexdef
-----------------
lower(f2)
(1 row)
and before 7.4 we don't support multicolumn functional indexes anyway.
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: DatabaseMetaData.getIndexInfo and function-based indexes
2005-02-18 22:55 DatabaseMetaData.getIndexInfo and function-based indexes peter royal <proyal@pace2020.com>
2005-02-19 04:07 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Kris Jurka <books@ejurka.com>
2005-02-19 05:54 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Tom Lane <tgl@sss.pgh.pa.us>
@ 2005-02-19 14:02 ` peter royal <proyal@pace2020.com>
2005-02-19 19:27 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 8+ messages in thread
From: peter royal @ 2005-02-19 14:02 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-jdbc; Kris Jurka <books@ejurka.com>
On Feb 19, 2005, at 12:54 AM, Tom Lane wrote:
> Kris Jurka <books@ejurka.com> writes:
>> This is what is actually stored in the pg_attribute table as the
>> column
>> name for the index. Determining what the actual expression is would
>> involve decoding the pg_index.indexpr column with pg_get_expr, which
>> could
>> be done, but then some manual parsing would need to be done to split
>> this
>> into multiple columns for something like (upper(a), lower(b)). So the
>> driver can figure this information out, but doesn't presently.
>
> FYI, pg_get_indexdef makes that pretty simple in PG >= 7.4:
i'm mainly concerned about single-column functional indexes right now.
being able to get upper(a) as the column name would be enough now. but
tom's method for working with multi-column functional indices would be
a bonus too.
would a patch to have DMD.getIndexInfo() return this information be
accepted into the tree? if so, i'll work one up.
-pete
Attachments:
smime.p7s (application/pkcs7-signature, 2.3K) download
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: DatabaseMetaData.getIndexInfo and function-based indexes
2005-02-18 22:55 DatabaseMetaData.getIndexInfo and function-based indexes peter royal <proyal@pace2020.com>
2005-02-19 04:07 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Kris Jurka <books@ejurka.com>
2005-02-19 05:54 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Tom Lane <tgl@sss.pgh.pa.us>
2005-02-19 14:02 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes peter royal <proyal@pace2020.com>
@ 2005-02-19 19:27 ` Kris Jurka <books@ejurka.com>
2005-02-23 17:35 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes peter royal <proyal@pace2020.com>
0 siblings, 1 reply; 8+ messages in thread
From: Kris Jurka @ 2005-02-19 19:27 UTC (permalink / raw)
To: peter royal <proyal@pace2020.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-jdbc
On Sat, 19 Feb 2005, peter royal wrote:
> i'm mainly concerned about single-column functional indexes right now.
> being able to get upper(a) as the column name would be enough now. but
> tom's method for working with multi-column functional indices would be
> a bonus too.
>
> would a patch to have DMD.getIndexInfo() return this information be
> accepted into the tree? if so, i'll work one up.
Yes, a column name of "pg_expression_N" is rather useless. upper(a) may
not be a column name, but it is more accurate and informative.
Kris Jurka
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: DatabaseMetaData.getIndexInfo and function-based indexes
2005-02-18 22:55 DatabaseMetaData.getIndexInfo and function-based indexes peter royal <proyal@pace2020.com>
2005-02-19 04:07 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Kris Jurka <books@ejurka.com>
2005-02-19 05:54 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Tom Lane <tgl@sss.pgh.pa.us>
2005-02-19 14:02 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes peter royal <proyal@pace2020.com>
2005-02-19 19:27 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Kris Jurka <books@ejurka.com>
@ 2005-02-23 17:35 ` peter royal <proyal@pace2020.com>
2005-02-24 05:00 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Kris Jurka <books@ejurka.com>
2005-03-04 06:55 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Kris Jurka <books@ejurka.com>
0 siblings, 2 replies; 8+ messages in thread
From: peter royal @ 2005-02-23 17:35 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc; Tom Lane <tgl@sss.pgh.pa.us>
On Feb 19, 2005, at 2:27 PM, Kris Jurka wrote:
> On Sat, 19 Feb 2005, peter royal wrote:
>
>> i'm mainly concerned about single-column functional indexes right now.
>> being able to get upper(a) as the column name would be enough now. but
>> tom's method for working with multi-column functional indices would be
>> a bonus too.
>>
>> would a patch to have DMD.getIndexInfo() return this information be
>> accepted into the tree? if so, i'll work one up.
>
>
> Yes, a column name of "pg_expression_N" is rather useless. upper(a)
> may
> not be a column name, but it is more accurate and informative.
Patch + test cases attached.
-pete
Attachments:
getFunctionalIndices.patch (application/octet-stream, 4.5K) download
Index: org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v
retrieving revision 1.18
diff -u -r1.18 AbstractJdbc2DatabaseMetaData.java
--- org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java 11 Jan 2005 08:25:45 -0000 1.18
+++ org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java 23 Feb 2005 17:28:50 -0000
@@ -3858,6 +3858,15 @@
from = " FROM pg_class ct, pg_class ci, pg_index i, pg_attribute a, pg_am am ";
}
+ if( connection.haveMinimumServerVersion("7.4"))
+ {
+ select += " CASE i.indexprs WHEN null THEN a.attname ELSE pg_get_indexdef(ci.oid,a.attnum,false) END AS COLUMN_NAME, ";
+ }
+ else
+ {
+ select += " a.attname AS COLUMN_NAME, ";
+ }
+
String sql = select +
" ct.relname AS TABLE_NAME, NOT i.indisunique AS NON_UNIQUE, NULL AS INDEX_QUALIFIER, ci.relname AS INDEX_NAME, " +
" CASE i.indisclustered " +
@@ -3868,7 +3877,6 @@
" END " +
" END AS TYPE, " +
" a.attnum AS ORDINAL_POSITION, " +
- " a.attname AS COLUMN_NAME, " +
" NULL AS ASC_OR_DESC, " +
" ci.reltuples AS CARDINALITY, " +
" ci.relpages AS PAGES, " +
Index: org/postgresql/test/jdbc2/DatabaseMetaDataTest.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java,v
retrieving revision 1.32
diff -u -r1.32 DatabaseMetaDataTest.java
--- org/postgresql/test/jdbc2/DatabaseMetaDataTest.java 11 Jan 2005 08:25:48 -0000 1.32
+++ org/postgresql/test/jdbc2/DatabaseMetaDataTest.java 23 Feb 2005 17:28:51 -0000
@@ -33,7 +39,7 @@
protected void setUp() throws Exception
{
con = TestUtil.openDB();
- TestUtil.createTable( con, "testmetadata", "id int4, name text, updated timestamp" );
+ TestUtil.createTable( con, "testmetadata", "id int4, name text, updated timestamp, colour text, quest text" );
TestUtil.dropSequence( con, "sercoltest_b_seq");
TestUtil.dropSequence( con, "sercoltest_c_seq");
TestUtil.createTable( con, "sercoltest", "a int, b serial, c bigserial");
@@ -358,10 +364,46 @@
public void testIndexInfo() throws SQLException
{
- // At the moment just test that no exceptions are thrown KJ
+ Statement stmt = con.createStatement();
+ stmt.execute("create index idx_id on testmetadata (id)");
+ stmt.execute("create index idx_func_single on testmetadata (upper(colour))");
+ stmt.execute("create index idx_func_multi on testmetadata (upper(colour), upper(quest))");
+ stmt.execute("create index idx_func_mixed on testmetadata (colour, upper(quest))");
+
DatabaseMetaData dbmd = con.getMetaData();
assertNotNull(dbmd);
- ResultSet rs = dbmd.getIndexInfo(null, null, "pg_class", false, false);
+ ResultSet rs = dbmd.getIndexInfo(null, null, "testmetadata", false, false);
+
+ assertTrue(rs.next());
+ assertEquals("idx_func_mixed", rs.getString("INDEX_NAME"));
+ assertEquals(1, rs.getInt("ORDINAL_POSITION"));
+ assertEquals("colour", rs.getString("COLUMN_NAME"));
+
+ assertTrue(rs.next());
+ assertEquals("idx_func_mixed", rs.getString("INDEX_NAME"));
+ assertEquals(2, rs.getInt("ORDINAL_POSITION"));
+ assertEquals("upper(quest)", rs.getString("COLUMN_NAME"));
+
+ assertTrue(rs.next());
+ assertEquals("idx_func_multi", rs.getString("INDEX_NAME"));
+ assertEquals(1, rs.getInt("ORDINAL_POSITION"));
+ assertEquals("upper(colour)", rs.getString("COLUMN_NAME"));
+
+ assertTrue(rs.next());
+ assertEquals("idx_func_multi", rs.getString("INDEX_NAME"));
+ assertEquals(2, rs.getInt("ORDINAL_POSITION"));
+ assertEquals("upper(quest)", rs.getString("COLUMN_NAME"));
+
+ assertTrue(rs.next());
+ assertEquals("idx_func_single", rs.getString("INDEX_NAME"));
+ assertEquals(1, rs.getInt("ORDINAL_POSITION"));
+ assertEquals("upper(colour)", rs.getString("COLUMN_NAME"));
+
+ assertTrue(rs.next());
+ assertEquals("idx_id", rs.getString("INDEX_NAME"));
+ assertEquals(1, rs.getInt("ORDINAL_POSITION"));
+ assertEquals("id", rs.getString("COLUMN_NAME"));
+
rs.close();
}
smime.p7s (application/pkcs7-signature, 2.3K) download
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: DatabaseMetaData.getIndexInfo and function-based indexes
2005-02-18 22:55 DatabaseMetaData.getIndexInfo and function-based indexes peter royal <proyal@pace2020.com>
2005-02-19 04:07 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Kris Jurka <books@ejurka.com>
2005-02-19 05:54 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Tom Lane <tgl@sss.pgh.pa.us>
2005-02-19 14:02 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes peter royal <proyal@pace2020.com>
2005-02-19 19:27 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Kris Jurka <books@ejurka.com>
2005-02-23 17:35 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes peter royal <proyal@pace2020.com>
@ 2005-02-24 05:00 ` Kris Jurka <books@ejurka.com>
1 sibling, 0 replies; 8+ messages in thread
From: Kris Jurka @ 2005-02-24 05:00 UTC (permalink / raw)
To: peter royal <proyal@pace2020.com>; +Cc: pgsql-jdbc; Tom Lane <tgl@sss.pgh.pa.us>
On Wed, 23 Feb 2005, peter royal wrote:
> >> would a patch to have DMD.getIndexInfo() return this information be
> >> accepted into the tree? if so, i'll work one up.
>
> Patch + test cases attached.
Looks reasonable, but you've checked the 7.4+ functionality correctly in
the metadata call, but not in the test cases.
Kris Jurka
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: DatabaseMetaData.getIndexInfo and function-based indexes
2005-02-18 22:55 DatabaseMetaData.getIndexInfo and function-based indexes peter royal <proyal@pace2020.com>
2005-02-19 04:07 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Kris Jurka <books@ejurka.com>
2005-02-19 05:54 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Tom Lane <tgl@sss.pgh.pa.us>
2005-02-19 14:02 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes peter royal <proyal@pace2020.com>
2005-02-19 19:27 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes Kris Jurka <books@ejurka.com>
2005-02-23 17:35 ` Re: DatabaseMetaData.getIndexInfo and function-based indexes peter royal <proyal@pace2020.com>
@ 2005-03-04 06:55 ` Kris Jurka <books@ejurka.com>
1 sibling, 0 replies; 8+ messages in thread
From: Kris Jurka @ 2005-03-04 06:55 UTC (permalink / raw)
To: peter royal <proyal@pace2020.com>; +Cc: pgsql-jdbc; Tom Lane <tgl@sss.pgh.pa.us>
On Wed, 23 Feb 2005, peter royal wrote:
> >> would a patch to have DMD.getIndexInfo() return this information be
> >> accepted into the tree? if so, i'll work one up.
> >
> > Yes, a column name of "pg_expression_N" is rather useless. upper(a)
> > may not be a column name, but it is more accurate and informative.
>
> Patch + test cases attached.
I've applied this with some minor modifications:
- I've extended it to work for < 7.4 servers
- You had modified the SELECT column order to return COLUMN_NAME in
a different position than required by the spec.
- Fixed the test cases to pass for < 7.4 servers
Thanks.
Kris Jurka
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2005-03-04 06:55 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-02-18 22:55 DatabaseMetaData.getIndexInfo and function-based indexes peter royal <proyal@pace2020.com>
2005-02-19 04:07 ` Kris Jurka <books@ejurka.com>
2005-02-19 05:54 ` Tom Lane <tgl@sss.pgh.pa.us>
2005-02-19 14:02 ` peter royal <proyal@pace2020.com>
2005-02-19 19:27 ` Kris Jurka <books@ejurka.com>
2005-02-23 17:35 ` peter royal <proyal@pace2020.com>
2005-02-24 05:00 ` Kris Jurka <books@ejurka.com>
2005-03-04 06:55 ` Kris Jurka <books@ejurka.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox