From 84a4884373720a0133c43dfd58f239ef5e55280c Mon Sep 17 00:00:00 2001 From: totaj Date: Mon, 19 Dec 2022 14:40:50 +0800 Subject: [PATCH] Fix empty column. --- src/bin/psql/print.cpp | 6 +++-- .../regress/expected/create_compositetype.out | 25 +++++++++++++++++++ src/test/regress/sql/create_compositetype.sql | 11 ++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/bin/psql/print.cpp b/src/bin/psql/print.cpp index 886f0f16aa9..c6c62d0c928 100644 --- a/src/bin/psql/print.cpp +++ b/src/bin/psql/print.cpp @@ -780,7 +780,9 @@ static void print_aligned_text(const printTableContent* cont, FILE* fout) more_col_wrapping = col_count; curr_nl_line = 0; - check_memset_s(memset_s(header_done, col_count * sizeof(bool), false, col_count * sizeof(bool))); + if (col_count > 0) { + check_memset_s(memset_s(header_done, col_count * sizeof(bool), false, col_count * sizeof(bool))); + } while (more_col_wrapping) { if (opt_border == 2) { fputs(dformat->leftvrule, fout); @@ -809,7 +811,7 @@ static void print_aligned_text(const printTableContent* cont, FILE* fout) if (opt_border != 0 || format->wrap_right_border) fputs(!header_done[i] ? format->header_nl_right : " ", fout); - if (opt_border != 0 && i < col_count - 1) + if (opt_border != 0 && col_count > 0 && i < col_count - 1) fputs(dformat->midvrule, fout); } curr_nl_line++; diff --git a/src/test/regress/expected/create_compositetype.out b/src/test/regress/expected/create_compositetype.out index 12da8ec0885..c3e5ffd220d 100644 --- a/src/test/regress/expected/create_compositetype.out +++ b/src/test/regress/expected/create_compositetype.out @@ -6,6 +6,31 @@ drop type "01jfiejriouieraejijiosjoerqkjou含有中文字符feoajfoeuitoooeiajf NOTICE: identifier "01jfiejriouieraejijiosjoerqkjou含有中文字符feoajfoeuitoooeiajfo" will be truncated to "01jfiejriouieraejijiosjoerqkjou含有中文字符feoajfoeuitooo" create type pg_class as (a int); drop type public.pg_class; +/* drop type to make a 0 column table */ +create type s_type as (a int, b text); +create table t_zero_col(a s_type); +insert into t_zero_col values((1, '1')); +select * from t_zero_col order by 1; + a +------- + (1,1) +(1 row) + +drop type s_type cascade; +NOTICE: drop cascades to table t_zero_col column a +select * from t_zero_col; +-- +(1 row) + +insert into t_zero_col values((2, '1')); +ERROR: INSERT has more expressions than target columns +LINE 1: insert into t_zero_col values((2, '1')); + ^ +insert into t_zero_col values(null); +ERROR: INSERT has more expressions than target columns +LINE 1: insert into t_zero_col values(null); + ^ +drop table t_zero_col; create table t_group (a int, b compfoo) WITH (orientation=row); insert into t_group values (1,(1,'Simon1')); insert into t_group values (2,(2,'Simon2')); diff --git a/src/test/regress/sql/create_compositetype.sql b/src/test/regress/sql/create_compositetype.sql index 72b3b86cdc2..90d3a1fcd7e 100644 --- a/src/test/regress/sql/create_compositetype.sql +++ b/src/test/regress/sql/create_compositetype.sql @@ -6,6 +6,17 @@ drop type "01jfiejriouieraejijiosjoerqkjou含有中文字符feoajfoeuitoooeiajf create type pg_class as (a int); drop type public.pg_class; +/* drop type to make a 0 column table */ +create type s_type as (a int, b text); +create table t_zero_col(a s_type); +insert into t_zero_col values((1, '1')); +select * from t_zero_col order by 1; +drop type s_type cascade; +select * from t_zero_col; +insert into t_zero_col values((2, '1')); +insert into t_zero_col values(null); +drop table t_zero_col; + create table t_group (a int, b compfoo) WITH (orientation=row); insert into t_group values (1,(1,'Simon1')); insert into t_group values (2,(2,'Simon2')); -- Gitee