This patch accounts for the behaviour of the backend when a table with a primary key constraint is created. The implicitly created index is named based on the table name with _pkey (truncating the table name as necessary), which may collide if the table name is not unique in the first (maxnamelen-5) characters. Not sure if this should be considered a bug in the jdbc driver or the server. For example, using psql: test=# create table t_345678901234567890123456789_a (pk int not null primary key); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 't_345678901234567890123456_pkey' for table 't_345678901234567890123456789_a' CREATE test=# create table t_345678901234567890123456789_b (pk int not null primary key); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 't_345678901234567890123456_pkey' for table 't_345678901234567890123456789_b' ERROR: index named "t_345678901234567890123456_pkey" already exists test=# I'm not convinced this patch is the "right thing" to do though. Index: src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java,v retrieving revision 1.13 diff -u -u -r1.13 AbstractJdbc1DatabaseMetaData.java --- src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java 2002/12/11 21:02:58 1.13 +++ src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java 2002/12/17 03:28:17 @@ -1528,7 +1528,10 @@ */ public int getMaxTableNameLength() throws SQLException { - return getMaxNameLength(); + // We must be unique in the first (namelength - 5) characters + // as the backend appends _pkey to generate an index name for primary + // key constraints when a table is created. + return getMaxNameLength() - 5; } /*