clickhouse-java icon indicating copy to clipboard operation
clickhouse-java copied to clipboard

Please implement com.clickhouse.jdbc.ClickHouseDatabaseMetaData.getPrimaryKeys()

Open lukaseder opened this issue 1 year ago • 1 comments

The current implementation of com.clickhouse.jdbc.ClickHouseDatabaseMetaData.getPrimaryKeys() in com.clickhouse:clickhouse-jdbc:0.6.0-patch4 just returns an empty ResultSet, though I think it would be relatively simple to implement this correctly.

For my own purposes, I run a query like this one:

select
  system.tables.database,
  system.tables.name,
  (('KEY_' || system.tables.name) || '_PRIMARY') constraint_name,
  trim(c.1) column_name,
  c.2 column_index
from system.tables 
  array join arrayZip(splitByChar(',', primary_key), arrayEnumerate(splitByChar(',', primary_key))) as c
where (
  system.tables.primary_key <> ''
  and system.tables.database in ('default')
)

It generates a synthetic constraint name, because apparently the original name isn't stored in the catalog. Feel free to re-use this in some way in the driver.

lukaseder avatar May 02 '24 13:05 lukaseder

@lukaseder thank you for reporting the issue. We will look into how to implement this.

chernser avatar May 05 '24 05:05 chernser