mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-21 01:00:48 +00:00
Support conversion for postgres numeric without precision and scale
This commit is contained in:
parent
80e6ad7aae
commit
2aad067e7c
@ -54,19 +54,30 @@ static DataTypePtr convertPostgreSQLDataType(std::string & type, bool is_nullabl
|
|||||||
res = std::make_shared<DataTypeDate>();
|
res = std::make_shared<DataTypeDate>();
|
||||||
else if (type.starts_with("numeric"))
|
else if (type.starts_with("numeric"))
|
||||||
{
|
{
|
||||||
/// Numeric and decimal will both end up here as numeric.
|
/// Numeric and decimal will both end up here as numeric. If it has type and precision,
|
||||||
res = DataTypeFactory::instance().get(type);
|
/// there will be Numeric(x, y), otherwise just Numeric
|
||||||
uint32_t precision = getDecimalPrecision(*res);
|
uint32_t precision, scale;
|
||||||
uint32_t scale = getDecimalScale(*res);
|
if (type.ends_with(")"))
|
||||||
|
{
|
||||||
|
res = DataTypeFactory::instance().get(type);
|
||||||
|
precision = getDecimalPrecision(*res);
|
||||||
|
scale = getDecimalScale(*res);
|
||||||
|
|
||||||
|
if (precision <= DecimalUtils::maxPrecision<Decimal32>())
|
||||||
|
res = std::make_shared<DataTypeDecimal<Decimal32>>(precision, scale);
|
||||||
|
else if (precision <= DecimalUtils::maxPrecision<Decimal64>())
|
||||||
|
res = std::make_shared<DataTypeDecimal<Decimal64>>(precision, scale);
|
||||||
|
else if (precision <= DecimalUtils::maxPrecision<Decimal128>())
|
||||||
|
res = std::make_shared<DataTypeDecimal<Decimal128>>(precision, scale);
|
||||||
|
else if (precision <= DecimalUtils::maxPrecision<Decimal256>())
|
||||||
|
res = std::make_shared<DataTypeDecimal<Decimal256>>(precision, scale);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
precision = DecimalUtils::maxPrecision<Decimal128>();
|
||||||
|
res = std::make_shared<DataTypeDecimal<Decimal128>>(precision, precision);
|
||||||
|
}
|
||||||
|
|
||||||
if (precision <= DecimalUtils::maxPrecision<Decimal32>())
|
|
||||||
res = std::make_shared<DataTypeDecimal<Decimal32>>(precision, scale);
|
|
||||||
else if (precision <= DecimalUtils::maxPrecision<Decimal64>())
|
|
||||||
res = std::make_shared<DataTypeDecimal<Decimal64>>(precision, scale);
|
|
||||||
else if (precision <= DecimalUtils::maxPrecision<Decimal128>())
|
|
||||||
res = std::make_shared<DataTypeDecimal<Decimal128>>(precision, scale);
|
|
||||||
else if (precision <= DecimalUtils::maxPrecision<Decimal256>())
|
|
||||||
res = std::make_shared<DataTypeDecimal<Decimal256>>(precision, scale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!res)
|
if (!res)
|
||||||
|
@ -63,13 +63,13 @@ def test_postgres_conversions(started_cluster):
|
|||||||
cursor.execute(
|
cursor.execute(
|
||||||
'''CREATE TABLE IF NOT EXISTS test_types (
|
'''CREATE TABLE IF NOT EXISTS test_types (
|
||||||
a smallint, b integer, c bigint, d real, e double precision, f serial, g bigserial,
|
a smallint, b integer, c bigint, d real, e double precision, f serial, g bigserial,
|
||||||
h timestamp, i date, j numeric(5, 5), k decimal(5, 5))''')
|
h timestamp, i date, j decimal(5, 5), k numeric)''')
|
||||||
node1.query('''
|
node1.query('''
|
||||||
INSERT INTO TABLE FUNCTION postgresql('postgres1:5432', 'clickhouse', 'test_types', 'postgres', 'mysecretpassword') VALUES
|
INSERT INTO TABLE FUNCTION postgresql('postgres1:5432', 'clickhouse', 'test_types', 'postgres', 'mysecretpassword') VALUES
|
||||||
(-32768, -2147483648, -9223372036854775808, 1.12345, 1.1234567890, 2147483647, 9223372036854775807, '2000-05-12 12:12:12', '2000-05-12', 0.2, 0.2)''')
|
(-32768, -2147483648, -9223372036854775808, 1.12345, 1.1234567890, 2147483647, 9223372036854775807, '2000-05-12 12:12:12', '2000-05-12', 0.22222, 0.22222)''')
|
||||||
result = node1.query('''
|
result = node1.query('''
|
||||||
SELECT * FROM postgresql('postgres1:5432', 'clickhouse', 'test_types', 'postgres', 'mysecretpassword')''')
|
SELECT a, b, c, d, e, f, g, h, i, j, toDecimal32(k, 5) FROM postgresql('postgres1:5432', 'clickhouse', 'test_types', 'postgres', 'mysecretpassword')''')
|
||||||
assert(result == '-32768\t-2147483648\t-9223372036854775808\t1.12345\t1.123456789\t2147483647\t9223372036854775807\t2000-05-12 12:12:12\t2000-05-12\t0.20000\t0.20000\n')
|
assert(result == '-32768\t-2147483648\t-9223372036854775808\t1.12345\t1.123456789\t2147483647\t9223372036854775807\t2000-05-12 12:12:12\t2000-05-12\t0.22222\t0.22222\n')
|
||||||
|
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
'''CREATE TABLE IF NOT EXISTS test_array_dimensions
|
'''CREATE TABLE IF NOT EXISTS test_array_dimensions
|
||||||
|
Loading…
Reference in New Issue
Block a user