From 57147b96e787fcda5aa103ea8b25881be2e4de07 Mon Sep 17 00:00:00 2001 From: zhubin79 <18784715772@163.com> Date: Thu, 20 Mar 2025 11:02:56 +0800 Subject: [PATCH] =?UTF-8?q?max=5Flength=20=E8=BE=85=E5=8A=A9=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=AF=B9decimal=E7=B1=BB=E5=9E=8B=E5=A4=84=E7=90=86?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contrib/shark/expected/test_sysviews.out | 13 ++++++-- contrib/shark/shark--1.0.sql | 41 +++++++++++------------- contrib/shark/sql/test_sysviews.sql | 7 ++++ 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/contrib/shark/expected/test_sysviews.out b/contrib/shark/expected/test_sysviews.out index c993d8a3c7..9e71a2ed66 100644 --- a/contrib/shark/expected/test_sysviews.out +++ b/contrib/shark/expected/test_sysviews.out @@ -185,6 +185,11 @@ CREATE TABLE course credit DOUBLE PRECISION ); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "course_pkey" for table "course" +create table teacher_salary +( + tec_id int, + tec_salary decimal(10, 2) +); create or replace view teacher_info as select c.cla_name, t.tec_name, t.tec_job, t.tec_sex, t.tec_age from teacher t @@ -246,6 +251,7 @@ order by id; fk_depart_tec_id | F | F course | U | U course_pkey | PK | K + teacher_salary | U | U teacher_info | V | V t_log | U | U t_seq | SO | SO @@ -254,7 +260,7 @@ order by id; test_sub | FN | FN syn_tbl | SN | SN syn_tr | SN | SN -(21 rows) +(22 rows) select col.name, col.length, col.colid, col.status, col.prec, col.scale, col.iscomputed, col.isoutparam, col.isnullable, col.collation from sys.syscolumns col @@ -286,6 +292,8 @@ order by id, colid; cor_name | 34 | 2 | 0 | 0 | 34 | 0 | 0 | 1 | default cor_type | 24 | 3 | 8 | 0 | 24 | 0 | 0 | 0 | default credit | 8 | 4 | 8 | 0 | | 0 | 0 | 0 | + tec_id | 4 | 1 | 8 | 10 | | 0 | 0 | 0 | + tec_salary | 15 | 2 | 8 | 10 | 2 | 0 | 0 | 0 | cla_name | 24 | 1 | 8 | 0 | 24 | 0 | 0 | 0 | default tec_name | 24 | 2 | 8 | 0 | 24 | 0 | 0 | 0 | default tec_job | 19 | 3 | 8 | 0 | 19 | 0 | 0 | 0 | default @@ -294,7 +302,7 @@ order by id, colid; c1 | 4 | 1 | 8 | 10 | | 0 | 0 | 0 | c2 | 24 | 2 | 8 | 0 | 24 | 0 | 0 | 0 | default c3 | 8 | 3 | 8 | 26 | | 0 | 0 | 0 | -(30 rows) +(32 rows) select ind.name, ind.keycnt, ind."OrigFillFactor", ind.rows from sys.sysindexes ind left join pg_class c on c.oid = ind.indid @@ -331,6 +339,7 @@ drop function test_sub; drop procedure test_sum; drop table t_log; drop view teacher_info; +drop table teacher_salary; drop table course; drop table school_department; drop table class; diff --git a/contrib/shark/shark--1.0.sql b/contrib/shark/shark--1.0.sql index 7b1d04d6d3..7e1713921a 100644 --- a/contrib/shark/shark--1.0.sql +++ b/contrib/shark/shark--1.0.sql @@ -293,7 +293,7 @@ select from pg_synonym y; grant select on sys.sysobjects to public; -create or replace function sys.tsql_type_max_length_helper(in type text, in typelen int, in typemod int) +create or replace function sys.tsql_type_max_length_helper(in type text, in typelen smallint, in typemod int) returns smallint as $$ declare @@ -303,19 +303,19 @@ begin max_length := -1; if typelen != -1 then - case - when lower(type) in ('numeric', 'decimal') then - precision := ((typemod - 4) >> 16) & 65535; - /* Each four bits (decimal bits) takes up two bytes and then adds an additional overhead of eight bytes to the entire data. */ - max_length := (ceil((precision / 4 + 1) * 2 + 8))::smallint; - else max_length := typelen; - end case; - return max_length; + return typelen; end if; if typemod != -1 then - max_length = typemod; + if lower(type) in ('numeric', 'decimal') then + precision := ((typemod - 4) >> 16) & 65535; + /* Each four bits (decimal bits) takes up two bytes and then adds an additional overhead of eight bytes to the entire data. */ + max_length := (ceil((precision / 4 + 1) * 2 + 8))::smallint; + return max_length; + end if; + max_length = typemod::smallint; end if; + return max_length; end; $$ language plpgsql immutable strict; @@ -380,23 +380,20 @@ $$ language plpgsql immutable strict; create or replace function sys.tsql_type_scale_helper(in type text, in typemod int) returns int as $$ -declare - scale int; begin if type is null then - return -1; + return null; end if; + + if typemod = -1 then + return null; + end if; - if typemod != -1 then - return typemod; - end if; + if lower(type) in ('numeric', 'decimal') then + return (typemod - 4) & 65535; + end if; - case lower(type) - when 'decimal' then scale = (typemod - 4) & 65535; - when 'numeric' then scale = (typemod - 4) & 65535; - else scale = null; - end case; - return scale; + return typemod; end; $$ language plpgsql immutable strict; diff --git a/contrib/shark/sql/test_sysviews.sql b/contrib/shark/sql/test_sysviews.sql index 68e7cfb876..b54c0b95b3 100644 --- a/contrib/shark/sql/test_sysviews.sql +++ b/contrib/shark/sql/test_sysviews.sql @@ -59,6 +59,12 @@ CREATE TABLE course credit DOUBLE PRECISION ); +create table teacher_salary +( + tec_id int, + tec_salary decimal(10, 2) +); + create or replace view teacher_info as select c.cla_name, t.tec_name, t.tec_job, t.tec_sex, t.tec_age from teacher t @@ -135,6 +141,7 @@ drop function test_sub; drop procedure test_sum; drop table t_log; drop view teacher_info; +drop table teacher_salary; drop table course; drop table school_department; drop table class; -- Gitee