Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to lower version of clickhouse #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 40 additions & 50 deletions internal/database/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,31 +224,26 @@ func (db *clickhouseSQLDBRepository) DescribeDatabaseTable(ctx context.Context)
rows, err := db.Conn.QueryContext(
ctx,
`
SELECT c.table_schema,
c.table_name,
c.column_name,
c.column_type,
CASE c.is_nullable
WHEN 1 THEN 'YES'
ELSE 'NO'
END,
CASE cu.constraint_name
WHEN 'PRIMARY' THEN 'YES'
ELSE 'NO'
END,
c.column_default,
''
FROM information_schema.columns c
LEFT JOIN (SELECT icu.table_schema,
icu.table_name,
icu.column_name,
icu.constraint_name
FROM information_schema.key_column_usage icu
WHERE icu.constraint_name = 'PRIMARY') cu using (
table_schema, table_name, column_name)
WHERE ( c.table_schema = currentDatabase()
OR c.table_schema = '' )
AND c.table_name NOT LIKE '%inner%'
SELECT
c.database ,
c.table ,
c.name,
c.type ,
CASE
WHEN c.type LIKE 'Nullable(%)' THEN 'YES'
ELSE 'NO'
END,
CASE
WHEN c.is_in_primary_key THEN 'YES'
ELSE 'NO'
END ,
c.default_expression,
''
FROM
system.columns c
WHERE ( c.database = currentDatabase()
OR c.database = '' )
AND c.table NOT LIKE '%inner%'
`)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -279,31 +274,26 @@ func (db *clickhouseSQLDBRepository) DescribeDatabaseTableBySchema(ctx context.C
rows, err := db.Conn.QueryContext(
ctx,
`
SELECT c.table_schema,
c.table_name,
c.column_name,
c.column_type,
CASE c.is_nullable
WHEN 1 THEN 'YES'
ELSE 'NO'
END,
CASE cu.constraint_name
WHEN 'PRIMARY' THEN 'YES'
ELSE 'NO'
END,
c.column_default,
''
FROM information_schema.columns c
LEFT JOIN (SELECT icu.table_schema,
icu.table_name,
icu.column_name,
icu.constraint_name
FROM information_schema.key_column_usage icu
WHERE icu.constraint_name = 'PRIMARY') cu using (
table_schema, table_name, column_name)
WHERE ( c.table_schema = ?
OR c.table_schema = '' )
AND c.table_name NOT LIKE '%inner%'
SELECT
c.database ,
c.table ,
c.name,
c.type ,
CASE
WHEN c.type LIKE 'Nullable(%)' THEN 'YES'
ELSE 'NO'
END,
CASE
WHEN c.is_in_primary_key THEN 'YES'
ELSE 'NO'
END ,
c.default_expression,
''
FROM
system.columns c
WHERE ( c.database = ?
OR c.database = '' )
AND c.table NOT LIKE '%inner%'
`, schemaName)
if err != nil {
log.Println("schema", schemaName, err.Error())
Expand Down