ClickHouse / clickhouse-java

ClickHouse Java Clients & JDBC Driver
https://clickhouse.com
Apache License 2.0
1.44k stars 529 forks source link

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

Open lukaseder opened 5 months ago

lukaseder commented 5 months ago

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.

chernser commented 4 months ago

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