Files
openGauss-server/src/test/regress/sql/single_node_regex_temp.sql

223 lines
13 KiB
SQL

-- test regexp_count(source_char, pattern [, position [, match_param] ])
set behavior_compat_options = aformat_regexp_match;
select regexp_count('abc', '^a');
select regexp_count('abc', '');
select regexp_count(null, '');
select regexp_count(null, null);
select regexp_count('abc', null);
select regexp_count('abc'||chr(10)||'def', '^(a|d)');
select regexp_count('abc'||chr(10)||'def', '^(a|d)', 1, 'm');
select regexp_count('abc'||chr(13)||chr(10)||'def', '^(a|d)', 1, 'm');
select regexp_count('abc'||chr(13)||chr(10)||'def', '^(a|d)', 1, 'n');
select regexp_count('abc'||chr(13)||chr(10)||'def', '^(a|d)', 1, 'p');
select regexp_count('abc'||chr(13)||chr(10)||'def', '^(a|d)', 1, 'w');
select regexp_count('abc'||chr(10)||'def', 'abc.d');
select regexp_count('abc'||chr(10)||'def', 'abc.d', 1, 'w');
select regexp_count('abc'||chr(10)||'def', 'abc.d', 1, 'g');
select regexp_count('abc'||chr(10)||'def', 'abc.d', 1, 'p');
select regexp_count('abc'||chr(10)||'def', 'abc.d', 2, 'w');
select regexp_count('abc'||chr(10)||'def', 'abc.d', null, 'w');
select regexp_count('abc'||chr(10)||'def', 'abc.d', 1000, 'w');
select regexp_count('abc'||chr(10)||'def', 'abc.d', 1000, null);
select regexp_count('abc', 'b', 0, '');
select regexp_count('abc', 'b', -1, '');
select regexp_count(null, 'b', -1, '');
select regexp_count(null, 'b', 1, 'g');
select regexp_count('abc', null, 1, 'g');
select regexp_count('abc def', '[a-z]{0,}');
select regexp_count('abc def', '[a-z]*');
select regexp_count('abc def', '[a-z]+');
select regexp_count('smishtm1_23','^\w+$',3);
select regexp_count('smishtm1_23','\w+$',3);
select regexp_count('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 5);
select regexp_count('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 20);
select regexp_count('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 35);
select regexp_count('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 36);
create table regexptable(id int,char_value CHAR(255), nchar_value NCHAR(255), varchar2_value VARCHAR2(255), nvarchar2_value NVARCHAR2(255), clob_value CLOB, text_value TEXT);
insert into regexptable values(1,'123jui','56700986.58 ','ring1023','smishtm1_23','qwe@qq.com','homeoooo9876000');
insert into regexptable values(2,'rooob000','-89098.980 ','9999.99900','j_ack_990','123@sina.com','-765489097.07658');
insert into regexptable values(3,'ring1023','9999.99900 ','marry_10','marry_10','qwe@11.cm','kingqueen0980_');
insert into regexptable values(4,'happyeveryday999','-900876','KINGGGkingooo765','_123abc','rty@qq.com','oplplPPPPPP11098');
insert into regexptable values(5,'clobbiger9098','654799009.9076','KINGkoo5','__acbcbf__','qwe@sina.com','oplplPPPPPP11098');
insert into regexptable values(6,'homeoooo9876000','-765489097.07658','KINGKkingooo098','kingqueen0980_','123@163.com','oplplPPPPPP11098');
insert into regexptable values(7,regexp_count('1233444',''),regexp_count('1233444',''),regexp_count('1233444','1'),regexp_count('1233444','2'),regexp_count('1233444','3'),regexp_count('1233444','4'));
select id, regexp_count(char_value,'^[A-Za-z0-9]+$',1) as result , char_value from regexptable order by 1, 2, 3;
--error
select id, regexp_count(char_value,'^[A-Za-z0-9]+$',2) as result , char_value from regexptable order by 1, 2, 3;
select id, regexp_count(nchar_value,'^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$') as result , nchar_value from regexptable order by 1, 2, 3;
--error
select id, regexp_count(nchar_value,'^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$',2) as result , nchar_value from regexptable order by 1, 2, 3;
select id, regexp_count(varchar2_value,'^.{3,8}$',1,'i') as result , varchar2_value from regexptable order by 1, 2, 3;
-- test regexp_instr(source_char, pattern [, position [, occurrence [, return_opt [, match_param]]]])
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '');
select regexp_instr(null, '');
select regexp_instr('abc', '');
select regexp_instr('abc', null);
select regexp_instr(null, 'b', 0);
select regexp_instr(null, 'b', 1);
select regexp_instr('abc', 'b', null);
select regexp_instr('abc', 'b', 1, null);
select regexp_instr('abc', 'b', -1, '');
select regexp_instr(null, 'b', -1, '');
select regexp_instr(null, 'b', 1, -1);
select regexp_instr(null, 'b', 1, 0);
select regexp_instr('abc', null, 1, -1);
select regexp_instr('abc', null, 1, 1, -1);
select regexp_instr('abc', null, 1, 1, 0);
select regexp_instr('abc def', '[a-z]{0,}', 1, 1);
select regexp_instr('abc def', '[a-z]{0,}', 1, 2);
select regexp_instr('abc def', '[a-z]{0,}', 1, 3);
select regexp_instr('abc def', '[a-z]{0,}', 1, 4);
select regexp_instr('abc def', '[a-z]{0,}', 1000);
select regexp_instr('abc def', '[a-z]{0,}', 7);
select regexp_instr('abc def', '[a-z]{0,}', 8);
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', null);
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+');
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 0, 6);
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', -1, 6);
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 1, 0);
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', null, 1);
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 1, null);
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 1, 6, 0);
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 1, 6, -1);
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 1, 6, 1);
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 5, 5);
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 5, 5, 2);
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 100, 5);
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 100, 0);
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 100, -1);
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 1, 100);
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[s|r|p][[:alpha:]]{6}', 3, 2, 0, 'i');
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[s|r|p][[:alpha:]]{6}', 3, 2, 1, 'i');
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[s|r|p][[:alpha:]]{6}', 3, 2, 1, 'c');
select regexp_instr('500 OMG Parkway, Redwood Shores, CA', '[s|r|p][[:alpha:]]{6}', 3, 2, 1, 'g');
select regexp_instr('abc'||chr(10)||'def', '^(a|d)?.', 1, 2, 0, 'm');
select regexp_instr('abc'||chr(10)||'def', '^(a|d)?.', 1, 2, 1, 'm');
select regexp_instr('smishtm1_23','^\w+$',3);
select regexp_instr('smishtm1_23','\w+$',3);
-- test regexp_substr(source_char, pattern [, position [, occurrence [, match_param]]])
select regexp_substr('', '[^ ]+');
select regexp_substr(null, '[^ ]+');
select regexp_substr(null, '');
select regexp_substr('abc', '');
select regexp_substr('abc', null);
select regexp_substr(null, 'b', 0);
select regexp_substr(null, 'b', 1);
select regexp_substr('abc', 'b', null);
select regexp_substr('abc', 'b', 1, null);
select regexp_substr('abc', 'b', -1, '');
select regexp_substr(null, 'b', -1, '');
select regexp_substr(null, 'b', 1, -1);
select regexp_substr(null, 'b', 1, 0);
select regexp_substr(null, 'b', 1, 1);
select regexp_substr('smishtm1_23','^\w+$',3,1);
select regexp_substr('abc def', '[a-z]{0,}', 7);
select regexp_substr('abc def', '[a-z]{0,}', 8);
select regexp_substr('abc def', '[a-z]{0,}', 9);
select regexp_substr('sping'||chr(10)||'sppkg', 'sp.+g');
select regexp_substr('500 OMG Parkway, Redwood Shores, CA', '');
select regexp_substr('500 OMG Parkway, Redwood Shores, CA', null);
select regexp_substr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+');
select regexp_substr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', null);
select regexp_substr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 0);
select regexp_substr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 1);
select regexp_substr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 1000);
select regexp_substr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 9);
select regexp_substr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 9, null);
select regexp_substr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 9, 0);
select regexp_substr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 9, 1);
select regexp_substr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 9, 3);
select regexp_substr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 9, 5);
select regexp_substr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 9, 4, '');
select regexp_substr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 9, 4, 'g');
select regexp_substr('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', 9, 4, null);
select regexp_substr('', '^(a|d)?.', 1, 2, 'm');
select regexp_substr(null, '^(a|d)?.', 1, 2, 'm');
select regexp_substr('abc'||chr(10)||'def', null, 1, 2, 'm');
select regexp_substr('abc'||chr(10)||'def', '', 1, 2, 'm');
select regexp_substr('abc'||chr(10)||'def', '^(a|d)?.', 1, 2, 'm');
select regexp_substr('abc'||chr(10)||'def', '^(a|d)?.', 1, null, 'm');
-- test regexp_replace(source_char, pattern [, replace_str [, position [, occurrence [, match_param]]]])
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+');
select regexp_replace('', '[^ ]+');
select regexp_replace('abc', '');
select regexp_replace('abc', null);
select regexp_replace(null, '[^ ]+');
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '');
select regexp_replace('', '[^ ]+', '-', 1);
select regexp_replace(null, '[^ ]+', '-', 1);
select regexp_replace(null, 'b', 'a', 0);
select regexp_replace(null, 'b', 'a', 1);
select regexp_replace('abc', 'b', 'a', null);
select regexp_replace('abc', 'b', 'a', 1, null);
select regexp_replace('abc', 'b', 'a', -1, '');
select regexp_replace(null, 'b', 'a', -1, '');
select regexp_replace(null, 'b', 'a', 1, -1);
select regexp_replace(null, 'b', 'a', 1, 0);
select regexp_replace(null, 'b', 'a', 1, 1);
select regexp_replace('abc', 'b', null, 1, 1);
select regexp_replace('abc', 'b', null, 1, null);
select regexp_replace('abc', 'b', null, 1, -1);
select regexp_replace('abc', 'b', '-', null, -1, 'n');
select regexp_replace('sping'||chr(10)||'sppkg', 'sp.+g', '-');
select regexp_replace('smishtm1_23','^\w+$','*',3,1);
select regexp_replace('123abc', '[0-9]*','9',100);
select regexp_replace('', '[a-z]{0,}', '$');
select regexp_replace('a', '[a-z]{0,}', '$');
select regexp_replace('abc def', '[a-z]{0,}', '$');
select regexp_replace('abc def', '[a-z]{0,}', '$', 3);
select regexp_replace('abc def', '[a-z]{0,}', '$', 4);
select regexp_replace('abc def', '[a-z]{0,}', '$', 5);
select regexp_replace('abc def', '[a-z]{0,}', '$', 7);
select regexp_replace('abc def', '[a-z]{0,}', '$', 8);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '', '-', null);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '', '-', 1);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', null, '-', 1);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', '', 1);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', null, 1);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', '-', 0);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', '-', 1000);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', '-', 5);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', '-', 34);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', '-', 35);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', '-', 1, -1);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', '-', 1, 0);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', '-', 1, 1);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', '-', 1, 6);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', '-', 1, 7);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', '-', 1, null);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', '-', 1, 2, null);
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', '-', 1, 2, '');
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', '-', 1, 2, 'm');
select regexp_replace('500 OMG Parkway, Redwood Shores, CA', '[^ ]+', '-', 1, 2, 'g');
select regexp_replace('abc'||chr(10)||'def', '^(a|d)?.', '-', 1, 2, 'm');
select regexp_replace('abc'||chr(13)||chr(10)||'def', '^(a|d)?.', '-', 1, 2, 'm');
set behavior_compat_options = '';
-- Test regexp_matches
select regexp_matches('abb', '(?<=a)b*');
select regexp_matches('a', 'a(?<=a)b*');
select regexp_matches('abc', 'a(?<=a)b*(?<=b)c*');
select regexp_matches('ab', 'a(?<=a)b*(?<=b)c*');
select regexp_matches('ab', 'a*(?<!a)b*');
select regexp_matches('ab', 'a*(?<!a)b+');
select regexp_matches('b', 'a*(?<!a)b+');
select regexp_matches('a', 'a(?<!a)b*');
select regexp_matches('b', '(?<=b)b');
select regexp_matches('foobar', '(?<=f)b+');
select regexp_matches('foobar', '(?<=foo)b+');
select regexp_matches('foobar', '(?<=oo)b+');
select regexp_matches('Programmer', '(\w)(.*?\1)', 'g');
SELECT regexp_matches('foo' || chr(10) || 'bar' || chr(10) || 'bequq' || chr(10) || 'baz', '^', 'mg');
SELECT regexp_matches('foo' || chr(10) || 'bar' || chr(10) || 'bequq' || chr(10) || 'baz', '$', 'mg');
SELECT regexp_matches('1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4' || chr(10), '^.?', 'mg');
create database tpcds dbcompatibility 'C';
\c tpcds
select regexp_matches('foo/bar/baz',
'^([^/]+?)(?:/([^/]+?))(?:/([^/]+?))?$', '');
\c regression
drop database tpcds;