!4401 修复alter table convert to问题
Merge pull request !4401 from suncan/fix_bug
This commit is contained in:
@ -8791,7 +8791,7 @@ static void sqlcmd_alter_prep_convert_charset(AlteredTableInfo* tab, Relation re
|
|||||||
Form_pg_attribute attTup = (Form_pg_attribute)GETSTRUCT(tuple);
|
Form_pg_attribute attTup = (Form_pg_attribute)GETSTRUCT(tuple);
|
||||||
int attnum = attTup->attnum;
|
int attnum = attTup->attnum;
|
||||||
if (attnum <= 0 || attTup->attisdropped || !type_is_collatable(attTup->atttypid) ||
|
if (attnum <= 0 || attTup->attisdropped || !type_is_collatable(attTup->atttypid) ||
|
||||||
get_charset_by_collation(attTup->attcollation) == cc->charset)
|
attTup->attcollation == targetcollid)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
transform = (Node*)makeVar(1, attnum, attTup->atttypid, attTup->atttypmod, attTup->attcollation, 0);
|
transform = (Node*)makeVar(1, attnum, attTup->atttypid, attTup->atttypmod, attTup->attcollation, 0);
|
||||||
|
@ -2455,6 +2455,77 @@ select distinct c3 from test_utf8mb4_bin;
|
|||||||
fxlP7sW8vA9hcYdKqRHLwDzRSaAjV1VrMZFYRsmjb9JpsIPdGu7Gpi6OzaOqmR
|
fxlP7sW8vA9hcYdKqRHLwDzRSaAjV1VrMZFYRsmjb9JpsIPdGu7Gpi6OzaOqmR
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- test alter table convert to
|
||||||
|
SET b_format_behavior_compat_options = 'enable_multi_charset';
|
||||||
|
drop table if exists test_convert_to;
|
||||||
|
NOTICE: table "test_convert_to" does not exist, skipping
|
||||||
|
create table test_convert_to(a text, b char(10))collate utf8mb4_general_ci;
|
||||||
|
insert into test_convert_to values('abcd'),('中文');
|
||||||
|
select pg_get_tabledef('test_convert_to');
|
||||||
|
pg_get_tabledef
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
SET search_path = public; +
|
||||||
|
CREATE TABLE test_convert_to ( +
|
||||||
|
a text CHARACTER SET "UTF8" COLLATE utf8mb4_general_ci, +
|
||||||
|
b character(10) CHARACTER SET "UTF8" COLLATE utf8mb4_general_ci+
|
||||||
|
) +
|
||||||
|
CHARACTER SET = "UTF8" COLLATE = "utf8mb4_general_ci" +
|
||||||
|
WITH (orientation=row, compression=no);
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
alter table test_convert_to convert to charset utf8mb4 collate utf8mb4_bin;
|
||||||
|
select pg_get_tabledef('test_convert_to');
|
||||||
|
pg_get_tabledef
|
||||||
|
--------------------------------------------------------------
|
||||||
|
SET search_path = public; +
|
||||||
|
CREATE TABLE test_convert_to ( +
|
||||||
|
a text CHARACTER SET "UTF8" COLLATE utf8mb4_bin, +
|
||||||
|
b character(10) CHARACTER SET "UTF8" COLLATE utf8mb4_bin+
|
||||||
|
) +
|
||||||
|
CHARACTER SET = "UTF8" COLLATE = "utf8mb4_bin" +
|
||||||
|
WITH (orientation=row, compression=no);
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
alter table test_convert_to convert to charset gbk collate gbk_bin;
|
||||||
|
select pg_get_tabledef('test_convert_to');
|
||||||
|
pg_get_tabledef
|
||||||
|
---------------------------------------------------------
|
||||||
|
SET search_path = public; +
|
||||||
|
CREATE TABLE test_convert_to ( +
|
||||||
|
a text CHARACTER SET "GBK" COLLATE gbk_bin, +
|
||||||
|
b character(10) CHARACTER SET "GBK" COLLATE gbk_bin+
|
||||||
|
) +
|
||||||
|
CHARACTER SET = "GBK" COLLATE = "gbk_bin" +
|
||||||
|
WITH (orientation=row, compression=no);
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
select * from test_convert_to;
|
||||||
|
a | b
|
||||||
|
------+---
|
||||||
|
abcd |
|
||||||
|
中文 |
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
|
alter table test_convert_to convert to charset default;
|
||||||
|
select pg_get_tabledef('test_convert_to');
|
||||||
|
pg_get_tabledef
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
SET search_path = public; +
|
||||||
|
CREATE TABLE test_convert_to ( +
|
||||||
|
a text CHARACTER SET "UTF8" COLLATE utf8mb4_general_ci, +
|
||||||
|
b character(10) CHARACTER SET "UTF8" COLLATE utf8mb4_general_ci+
|
||||||
|
) +
|
||||||
|
CHARACTER SET = "UTF8" COLLATE = "utf8mb4_general_ci" +
|
||||||
|
WITH (orientation=row, compression=no);
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
select * from test_convert_to;
|
||||||
|
a | b
|
||||||
|
------+---
|
||||||
|
abcd |
|
||||||
|
中文 |
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
create database b_ascii encoding = 0;
|
create database b_ascii encoding = 0;
|
||||||
\c b_ascii
|
\c b_ascii
|
||||||
set client_encoding = utf8;
|
set client_encoding = utf8;
|
||||||
|
@ -579,6 +579,25 @@ select count(*) from test_utf8mb4_bin group by c2, c3;
|
|||||||
select distinct c2 from test_utf8mb4_bin;
|
select distinct c2 from test_utf8mb4_bin;
|
||||||
select distinct c3 from test_utf8mb4_bin;
|
select distinct c3 from test_utf8mb4_bin;
|
||||||
|
|
||||||
|
-- test alter table convert to
|
||||||
|
SET b_format_behavior_compat_options = 'enable_multi_charset';
|
||||||
|
drop table if exists test_convert_to;
|
||||||
|
create table test_convert_to(a text, b char(10))collate utf8mb4_general_ci;
|
||||||
|
insert into test_convert_to values('abcd'),('中文');
|
||||||
|
select pg_get_tabledef('test_convert_to');
|
||||||
|
|
||||||
|
alter table test_convert_to convert to charset utf8mb4 collate utf8mb4_bin;
|
||||||
|
select pg_get_tabledef('test_convert_to');
|
||||||
|
|
||||||
|
alter table test_convert_to convert to charset gbk collate gbk_bin;
|
||||||
|
select pg_get_tabledef('test_convert_to');
|
||||||
|
select * from test_convert_to;
|
||||||
|
|
||||||
|
alter table test_convert_to convert to charset default;
|
||||||
|
select pg_get_tabledef('test_convert_to');
|
||||||
|
select * from test_convert_to;
|
||||||
|
|
||||||
|
|
||||||
create database b_ascii encoding = 0;
|
create database b_ascii encoding = 0;
|
||||||
\c b_ascii
|
\c b_ascii
|
||||||
set client_encoding = utf8;
|
set client_encoding = utf8;
|
||||||
|
Reference in New Issue
Block a user