From f570b5ac1061334467fcbc10131cf3747978d676 Mon Sep 17 00:00:00 2001 From: aiwenmo <32723967+aiwenmo@users.noreply.github.com> Date: Wed, 24 Jan 2024 15:13:12 +0800 Subject: [PATCH] [Fix-2877] Fix postgre type converter (#3052) Co-authored-by: wenmo <32723967+wenmo@users.noreply.github.com> --- .../dinky/metadata/convert/PostgreSqlTypeConvert.java | 2 +- .../org/dinky/metadata/query/PostgreSqlQuery.java | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/dinky-metadata/dinky-metadata-postgresql/src/main/java/org/dinky/metadata/convert/PostgreSqlTypeConvert.java b/dinky-metadata/dinky-metadata-postgresql/src/main/java/org/dinky/metadata/convert/PostgreSqlTypeConvert.java index a0e84d6f5c..64315decca 100644 --- a/dinky-metadata/dinky-metadata-postgresql/src/main/java/org/dinky/metadata/convert/PostgreSqlTypeConvert.java +++ b/dinky-metadata/dinky-metadata-postgresql/src/main/java/org/dinky/metadata/convert/PostgreSqlTypeConvert.java @@ -30,7 +30,7 @@ public class PostgreSqlTypeConvert extends AbstractJdbcTypeConvert { public PostgreSqlTypeConvert() { this.convertMap.clear(); - register("smallint", ColumnType.SHORT, ColumnType.JAVA_LANG_SHORT); + register("smallint", ColumnType.INT, ColumnType.INTEGER); register("int2", ColumnType.SHORT, ColumnType.JAVA_LANG_SHORT); register("smallserial", ColumnType.SHORT, ColumnType.JAVA_LANG_SHORT); register("serial2", ColumnType.SHORT, ColumnType.JAVA_LANG_SHORT); diff --git a/dinky-metadata/dinky-metadata-postgresql/src/main/java/org/dinky/metadata/query/PostgreSqlQuery.java b/dinky-metadata/dinky-metadata-postgresql/src/main/java/org/dinky/metadata/query/PostgreSqlQuery.java index 6da03929f5..1543bf6db1 100644 --- a/dinky-metadata/dinky-metadata-postgresql/src/main/java/org/dinky/metadata/query/PostgreSqlQuery.java +++ b/dinky-metadata/dinky-metadata-postgresql/src/main/java/org/dinky/metadata/query/PostgreSqlQuery.java @@ -51,8 +51,9 @@ public String tablesSql(String schemaName) { @Override public String columnsSql(String schemaName, String tableName) { - return "SELECT col.column_name as name\n" - + " , col.character_maximum_length as length\n" + return "SELECT col.column_name as name\n" + + " , COALESCE(col.character_maximum_length,datetime_precision)" + + " as length\n" + " , col.is_nullable as is_nullable\n" + " , col.numeric_precision as numeric_precision\n" + " , col.numeric_scale as numeric_scale\n" @@ -60,9 +61,9 @@ public String columnsSql(String schemaName, String tableName) { + " , col.udt_name as type\n" + " , (CASE WHEN (SELECT COUNT(*) FROM pg_constraint AS PC WHERE b.attnum" + " = ANY(PC.conkey) AND PC.contype = 'p' and PC.conrelid = c.oid) > 0 \n" - + "THEN 'PRI' ELSE '' END) AS key\n" - + " , col_description(c.oid, col.ordinal_position) AS comment\n" - + " , col.column_default AS column_default\n" + + "THEN 'PRI' ELSE '' END) as key\n" + + " , col_description(c.oid, col.ordinal_position) as comment\n" + + " , col.column_default as column_default\n" + "FROM information_schema.columns AS col\n" + " LEFT JOIN pg_namespace ns ON ns.nspname = col.table_schema\n" + " LEFT JOIN pg_class c ON col.table_name = c.relname AND"