missing code of 3f3b578e1074a00bfe3bcd51c34d45eae06a5f72: char/varchar length count.
This commit is contained in:
@ -675,7 +675,7 @@ Datum bpcharlen(PG_FUNCTION_ARGS)
|
|||||||
int len;
|
int len;
|
||||||
|
|
||||||
/* get number of bytes, ignoring trailing spaces */
|
/* get number of bytes, ignoring trailing spaces */
|
||||||
if (DB_IS_CMPT(PG_FORMAT)) {
|
if (DB_IS_CMPT(PG_FORMAT | B_FORMAT)) {
|
||||||
len = bcTruelen(arg);
|
len = bcTruelen(arg);
|
||||||
} else {
|
} else {
|
||||||
len = VARSIZE_ANY_EXHDR(arg);
|
len = VARSIZE_ANY_EXHDR(arg);
|
||||||
|
@ -921,8 +921,8 @@ template<bool calCharLength> int MbCharClipLen(const char* mbstr, int len, int l
|
|||||||
*/
|
*/
|
||||||
int pg_mbcharcliplen(const char* mbstr, int len, int limit)
|
int pg_mbcharcliplen(const char* mbstr, int len, int limit)
|
||||||
{
|
{
|
||||||
bool pgFormat = DB_IS_CMPT(PG_FORMAT);
|
bool calCharLength = DB_IS_CMPT(PG_FORMAT | B_FORMAT);
|
||||||
if (pgFormat) {
|
if (calCharLength) {
|
||||||
return MbCharClipLen<true>(mbstr, len, limit);
|
return MbCharClipLen<true>(mbstr, len, limit);
|
||||||
} else {
|
} else {
|
||||||
return MbCharClipLen<false>(mbstr, len, limit);
|
return MbCharClipLen<false>(mbstr, len, limit);
|
||||||
|
@ -269,9 +269,9 @@ select cast('s' as int);
|
|||||||
--------------- limit #,#-------------------
|
--------------- limit #,#-------------------
|
||||||
-- limit case in postgresql
|
-- limit case in postgresql
|
||||||
\c regression
|
\c regression
|
||||||
create table test(a int);
|
create table test_limit(a int);
|
||||||
insert into test values (1),(2),(3),(4),(5);
|
insert into test_limit values (1),(2),(3),(4),(5);
|
||||||
select * from test order by 1 limit 2,3;
|
select * from test_limit order by 1 limit 2,3;
|
||||||
a
|
a
|
||||||
---
|
---
|
||||||
3
|
3
|
||||||
@ -279,7 +279,7 @@ select * from test order by 1 limit 2,3;
|
|||||||
5
|
5
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
select * from test order by 1 limit 2,6;
|
select * from test_limit order by 1 limit 2,6;
|
||||||
a
|
a
|
||||||
---
|
---
|
||||||
3
|
3
|
||||||
@ -287,17 +287,17 @@ select * from test order by 1 limit 2,6;
|
|||||||
5
|
5
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
select * from test order by 1 limit 6,2;
|
select * from test_limit order by 1 limit 6,2;
|
||||||
a
|
a
|
||||||
---
|
---
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
drop table test;
|
drop table test_limit;
|
||||||
-- limit case in b
|
-- limit case in b
|
||||||
\c b
|
\c b
|
||||||
create table test(a int);
|
create table test_limit(a int);
|
||||||
insert into test values (1),(2),(3),(4),(5);
|
insert into test_limit values (1),(2),(3),(4),(5);
|
||||||
select * from test order by 1 limit 2,3;
|
select * from test_limit order by 1 limit 2,3;
|
||||||
a
|
a
|
||||||
---
|
---
|
||||||
3
|
3
|
||||||
@ -305,7 +305,7 @@ select * from test order by 1 limit 2,3;
|
|||||||
5
|
5
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
select * from test order by 1 limit 2,6;
|
select * from test_limit order by 1 limit 2,6;
|
||||||
a
|
a
|
||||||
---
|
---
|
||||||
3
|
3
|
||||||
@ -313,12 +313,12 @@ select * from test order by 1 limit 2,6;
|
|||||||
5
|
5
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
select * from test order by 1 limit 6,2;
|
select * from test_limit order by 1 limit 6,2;
|
||||||
a
|
a
|
||||||
---
|
---
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
drop table test;
|
drop table test_limit;
|
||||||
--------------timestampdiff-----------------
|
--------------timestampdiff-----------------
|
||||||
-- timestamp with time zone
|
-- timestamp with time zone
|
||||||
-- timestamp1 > timestamp2
|
-- timestamp1 > timestamp2
|
||||||
@ -634,8 +634,8 @@ select timestampdiff(second, '2018-01-01', now());
|
|||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
select timestampdiff(microsecond, '2018-01-01', now());
|
select timestampdiff(microsecond, '2018-01-01', now());
|
||||||
timestamp_diff
|
timestamp_diff
|
||||||
----------------
|
-----------------
|
||||||
--?.*
|
--?.*
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
@ -731,5 +731,79 @@ select timestampdiff(microsecond, '2018-01-01 01:01:01.000001', b) from timestam
|
|||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
drop table timestamp;
|
drop table timestamp;
|
||||||
|
-- test char/varchar length
|
||||||
|
create table char_test(a char(10),b varchar(10));
|
||||||
|
insert into char_test values('零一二三四五六七八九','零一二三四五六七八九');
|
||||||
|
insert into char_test values('零1二3四5六7八9','零1二3四5六7八9');
|
||||||
|
insert into char_test values('零1二3四5六7八9','零1二3四5六7八90');
|
||||||
|
ERROR: value too long for type character varying(10)
|
||||||
|
CONTEXT: referenced column: b
|
||||||
|
insert into char_test values('零1二3四5六7八90','零1二3四5六7八9');
|
||||||
|
ERROR: value too long for type character(10)
|
||||||
|
CONTEXT: referenced column: a
|
||||||
|
insert into char_test values('零0','零1二3');
|
||||||
|
insert into char_test values('零0 ','零1二3');
|
||||||
|
insert into char_test values('零0','零1二3 ');
|
||||||
|
insert into char_test values('','');
|
||||||
|
insert into char_test values(null,null);
|
||||||
|
insert into char_test values('0','0');
|
||||||
|
select length(a),length(b) from char_test;
|
||||||
|
length | length
|
||||||
|
--------+--------
|
||||||
|
10 | 10
|
||||||
|
10 | 10
|
||||||
|
2 | 4
|
||||||
|
2 | 4
|
||||||
|
2 | 6
|
||||||
|
0 | 0
|
||||||
|
|
|
||||||
|
1 | 1
|
||||||
|
(8 rows)
|
||||||
|
|
||||||
|
select lengthb(a),lengthb(b) from char_test;
|
||||||
|
lengthb | lengthb
|
||||||
|
---------+---------
|
||||||
|
30 | 30
|
||||||
|
20 | 20
|
||||||
|
10 | 8
|
||||||
|
10 | 8
|
||||||
|
10 | 10
|
||||||
|
10 | 0
|
||||||
|
|
|
||||||
|
10 | 1
|
||||||
|
(8 rows)
|
||||||
|
|
||||||
|
select bit_length(a),bit_length(b) from char_test;
|
||||||
|
bit_length | bit_length
|
||||||
|
------------+------------
|
||||||
|
240 | 240
|
||||||
|
160 | 160
|
||||||
|
32 | 64
|
||||||
|
32 | 64
|
||||||
|
32 | 80
|
||||||
|
0 | 0
|
||||||
|
|
|
||||||
|
8 | 8
|
||||||
|
(8 rows)
|
||||||
|
|
||||||
|
create index a on char_test(a);
|
||||||
|
create index b on char_test(b);
|
||||||
|
set enable_seqscan to off;
|
||||||
|
select * from char_test where a = '零0';
|
||||||
|
a | b
|
||||||
|
-----------+----------
|
||||||
|
零0 | 零1二3
|
||||||
|
零0 | 零1二3
|
||||||
|
零0 | 零1二3
|
||||||
|
(3 rows)
|
||||||
|
|
||||||
|
select * from char_test where b = '零1二3';
|
||||||
|
a | b
|
||||||
|
-----------+--------
|
||||||
|
零0 | 零1二3
|
||||||
|
零0 | 零1二3
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
|
drop table char_test;
|
||||||
\c regression
|
\c regression
|
||||||
drop database b;
|
drop database b;
|
||||||
|
@ -749,7 +749,7 @@ test: copy2 temp
|
|||||||
test: truncate
|
test: truncate
|
||||||
#test: temp_table
|
#test: temp_table
|
||||||
|
|
||||||
#test: b_compatibility
|
test: b_compatibility
|
||||||
test: hw_compatibility
|
test: hw_compatibility
|
||||||
test: hw_groupingsets hw_row_grouping_set
|
test: hw_groupingsets hw_row_grouping_set
|
||||||
test: char_truncation_common char_truncation_cast
|
test: char_truncation_common char_truncation_cast
|
||||||
|
@ -82,21 +82,21 @@ select cast('s' as int);
|
|||||||
--------------- limit #,#-------------------
|
--------------- limit #,#-------------------
|
||||||
-- limit case in postgresql
|
-- limit case in postgresql
|
||||||
\c regression
|
\c regression
|
||||||
create table test(a int);
|
create table test_limit(a int);
|
||||||
insert into test values (1),(2),(3),(4),(5);
|
insert into test_limit values (1),(2),(3),(4),(5);
|
||||||
select * from test order by 1 limit 2,3;
|
select * from test_limit order by 1 limit 2,3;
|
||||||
select * from test order by 1 limit 2,6;
|
select * from test_limit order by 1 limit 2,6;
|
||||||
select * from test order by 1 limit 6,2;
|
select * from test_limit order by 1 limit 6,2;
|
||||||
drop table test;
|
drop table test_limit;
|
||||||
|
|
||||||
-- limit case in b
|
-- limit case in b
|
||||||
\c b
|
\c b
|
||||||
create table test(a int);
|
create table test_limit(a int);
|
||||||
insert into test values (1),(2),(3),(4),(5);
|
insert into test_limit values (1),(2),(3),(4),(5);
|
||||||
select * from test order by 1 limit 2,3;
|
select * from test_limit order by 1 limit 2,3;
|
||||||
select * from test order by 1 limit 2,6;
|
select * from test_limit order by 1 limit 2,6;
|
||||||
select * from test order by 1 limit 6,2;
|
select * from test_limit order by 1 limit 6,2;
|
||||||
drop table test;
|
drop table test_limit;
|
||||||
|
|
||||||
--------------timestampdiff-----------------
|
--------------timestampdiff-----------------
|
||||||
-- timestamp with time zone
|
-- timestamp with time zone
|
||||||
@ -189,6 +189,29 @@ select timestampdiff(second, '2018-01-01 01:01:01.000001', b) from timestamp;
|
|||||||
select timestampdiff(microsecond, '2018-01-01 01:01:01.000001', b) from timestamp;
|
select timestampdiff(microsecond, '2018-01-01 01:01:01.000001', b) from timestamp;
|
||||||
drop table timestamp;
|
drop table timestamp;
|
||||||
|
|
||||||
|
-- test char/varchar length
|
||||||
|
create table char_test(a char(10),b varchar(10));
|
||||||
|
insert into char_test values('零一二三四五六七八九','零一二三四五六七八九');
|
||||||
|
insert into char_test values('零1二3四5六7八9','零1二3四5六7八9');
|
||||||
|
insert into char_test values('零1二3四5六7八9','零1二3四5六7八90');
|
||||||
|
insert into char_test values('零1二3四5六7八90','零1二3四5六7八9');
|
||||||
|
insert into char_test values('零0','零1二3');
|
||||||
|
insert into char_test values('零0 ','零1二3');
|
||||||
|
insert into char_test values('零0','零1二3 ');
|
||||||
|
insert into char_test values('','');
|
||||||
|
insert into char_test values(null,null);
|
||||||
|
insert into char_test values('0','0');
|
||||||
|
select length(a),length(b) from char_test;
|
||||||
|
select lengthb(a),lengthb(b) from char_test;
|
||||||
|
select bit_length(a),bit_length(b) from char_test;
|
||||||
|
|
||||||
|
create index a on char_test(a);
|
||||||
|
create index b on char_test(b);
|
||||||
|
set enable_seqscan to off;
|
||||||
|
select * from char_test where a = '零0';
|
||||||
|
select * from char_test where b = '零1二3';
|
||||||
|
drop table char_test;
|
||||||
|
|
||||||
\c regression
|
\c regression
|
||||||
|
|
||||||
drop database b;
|
drop database b;
|
||||||
|
Reference in New Issue
Block a user