tags:

views:

172

answers:

1

How does one do this? The SYSCOLUMNS system table only has columns for tables. SYSCHECKS has a REFERENCEDCOLUMNS object. Is there any way to get this.

I'm aware of the JDBC getPrimaryKeys call, but that doesn't get unique constraint columns.

A: 

http://stackoverflow.com/questions/845766/derby-constraints

It took some digging to find the above question; my question is a partially answered follow-up question to the one above.

Taking the CONSTRAINTID against SYSKEYS gives a CONGLOMERATEID, which when taken against SYSCONGLOMERATES yields a DESCRIPTOR. The DESCRIPTOR is a POJO that contains an int-array in the baseColumnPositions method. This int-array contains the COLUMNNUMBERS in SYSCOLUMNS of the columns in the constraint.

If querying in straight SQL, getting the DESCRIPTOR field yields a string with a CSV list of ints that have to be parsed. Fortunately for me, I happen to be working in Clojure, so calling the baseColumnPositions method and using the resulting int-array are trivial.

entaroadun