[improvement](pg jdbc)Support for automatically obtaining the precision of the postgresql timestamp type (#20909)

This commit is contained in:
zy-kkk
2023-06-16 23:41:09 +08:00
committed by GitHub
parent 367f64e7bd
commit fe18cfa2fb
5 changed files with 24 additions and 8 deletions

View File

@ -160,4 +160,9 @@ CREATE TABLE catalog_pg_test.test_insert (
CREATE TABLE catalog_pg_test.wkb_test (
id SERIAL PRIMARY KEY,
location bytea
);
);
CREATE TABLE catalog_pg_test.dt_test (
ts_field TIMESTAMP(3),
tzt_field TIMESTAMPTZ(3)
);

View File

@ -2656,4 +2656,11 @@ insert into catalog_pg_test.test12 values
insert into catalog_pg_test.test12 values
(2, '980dd890-f7fe-4fff-999d-873516108b2e');
INSERT INTO catalog_pg_test.wkb_test (location) SELECT ST_AsBinary(ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))',4326));
INSERT INTO catalog_pg_test.wkb_test (location) SELECT ST_AsBinary(ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))',4326));
INSERT INTO catalog_pg_test.dt_test (ts_field, tzt_field)
VALUES
(
'2023-06-16 12:34:56.123',
'2023-06-16 12:34:56.123+08'
);

View File

@ -67,7 +67,12 @@ public class JdbcPostgreSQLClient extends JdbcClient {
case "timestamp":
case "timestamptz":
// postgres can support microsecond
return ScalarType.createDatetimeV2Type(JDBC_DATETIME_SCALE);
int scale = fieldSchema.getDecimalDigits();
if (scale < 6) {
return ScalarType.createDatetimeV2Type(scale);
} else {
return ScalarType.createDatetimeV2Type(JDBC_DATETIME_SCALE);
}
case "date":
return ScalarType.createDateV2Type();
case "bool":

View File

@ -5,11 +5,6 @@
234 bcd
-- !in_tb --
111 abc
112 abd
113 abe
114 abf
115 abg
123 abc
123 abc
234 bcd
@ -2144,6 +2139,9 @@ true abc def 2022-10-11 1.234 1 2 99 2022-10-22T10:59:59 34.123
-- !wkb_test --
1 \\x01030000000100000005000000000000000000000000000000000000000000000000000000000000000000f03f000000000000f03f000000000000f03f000000000000f03f000000000000000000000000000000000000000000000000
-- !dt_test --
2023-06-16T12:34:56.123 2023-06-16T12:34:56.123
-- !test_insert1 --
doris1 18

View File

@ -70,6 +70,7 @@ suite("test_pg_jdbc_catalog", "p0") {
order_qt_test13 """ select * from test11 order by id; """
order_qt_test14 """ select * from test12 order by id; """
order_qt_wkb_test """ select * from wkb_test order by id; """
order_qt_dt_test """ select * from dt_test order by 1; """
// test insert
String uuid1 = UUID.randomUUID().toString();