Back to home page

OSCL-LXR

 
 

    


0001 --
0002 -- Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
0003 --
0004 --
0005 -- TEXT
0006 -- https://github.com/postgres/postgres/blob/REL_12_BETA2/src/test/regress/sql/text.sql
0007 
0008 SELECT string('this is a text string') = string('this is a text string') AS true;
0009 
0010 SELECT string('this is a text string') = string('this is a text strin') AS `false`;
0011 
0012 CREATE TABLE TEXT_TBL (f1 string) USING parquet;
0013 
0014 INSERT INTO TEXT_TBL VALUES ('doh!');
0015 INSERT INTO TEXT_TBL VALUES ('hi de ho neighbor');
0016 
0017 SELECT '' AS two, * FROM TEXT_TBL;
0018 
0019 -- As of 8.3 we have removed most implicit casts to text, so that for example
0020 -- this no longer works:
0021 -- Spark SQL implicit cast integer to string
0022 select length(42);
0023 
0024 -- But as a special exception for usability's sake, we still allow implicit
0025 -- casting to text in concatenations, so long as the other input is text or
0026 -- an unknown literal.  So these work:
0027 -- [SPARK-28033] String concatenation low priority than other arithmeticBinary
0028 select string('four: ') || 2+2;
0029 select 'four: ' || 2+2;
0030 
0031 -- but not this:
0032 -- Spark SQL implicit cast both side to string
0033 select 3 || 4.0;
0034 
0035 /*
0036  * various string functions
0037  */
0038 select concat('one');
0039 -- Spark SQL does not support YYYYMMDD, we replace it to yyyyMMdd
0040 select concat(1,2,3,'hello',true, false, to_date('20100309','yyyyMMdd'));
0041 select concat_ws('#','one');
0042 select concat_ws('#',1,2,3,'hello',true, false, to_date('20100309','yyyyMMdd'));
0043 select concat_ws(',',10,20,null,30);
0044 select concat_ws('',10,20,null,30);
0045 select concat_ws(NULL,10,20,null,30) is null;
0046 select reverse('abcde');
0047 select i, left('ahoj', i), right('ahoj', i) from range(-5, 6) t(i) order by i;
0048 -- [SPARK-28037] Add built-in String Functions: quote_literal
0049 -- select quote_literal('');
0050 -- select quote_literal('abc''');
0051 -- select quote_literal(e'\\');
0052 
0053 -- Skip these tests because Spark does not support variadic labeled argument
0054 -- check variadic labeled argument
0055 -- select concat(variadic array[1,2,3]);
0056 -- select concat_ws(',', variadic array[1,2,3]);
0057 -- select concat_ws(',', variadic NULL::int[]);
0058 -- select concat(variadic NULL::int[]) is NULL;
0059 -- select concat(variadic '{}'::int[]) = '';
0060 --should fail
0061 -- select concat_ws(',', variadic 10);
0062 
0063 -- [SPARK-27930] Replace format to format_string
0064 /*
0065  * format
0066  */
0067 select format_string(NULL);
0068 select format_string('Hello');
0069 select format_string('Hello %s', 'World');
0070 select format_string('Hello %%');
0071 select format_string('Hello %%%%');
0072 -- should fail
0073 select format_string('Hello %s %s', 'World');
0074 select format_string('Hello %s');
0075 select format_string('Hello %x', 20);
0076 -- check literal and sql identifiers
0077 -- [SPARK-27930] format_string can not fully support PostgreSQL's format
0078 -- select format_string('INSERT INTO %I VALUES(%L,%L)', 'mytab', 10, 'Hello');
0079 -- select format_string('%s%s%s','Hello', NULL,'World');
0080 -- select format_string('INSERT INTO %I VALUES(%L,%L)', 'mytab', 10, NULL);
0081 -- select format_string('INSERT INTO %I VALUES(%L,%L)', 'mytab', NULL, 'Hello');
0082 -- should fail, sql identifier cannot be NULL
0083 -- select format_string('INSERT INTO %I VALUES(%L,%L)', NULL, 10, 'Hello');
0084 -- check positional placeholders
0085 select format_string('%1$s %3$s', 1, 2, 3);
0086 select format_string('%1$s %12$s', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
0087 -- should fail
0088 select format_string('%1$s %4$s', 1, 2, 3);
0089 select format_string('%1$s %13$s', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
0090 --PostgreSQL throw ERROR:  format specifies argument 0, but arguments are numbered from 1
0091 select format_string('%0$s', 'Hello');
0092 -- [SPARK-27930] format_string can not fully support PostgreSQL's format
0093 -- select format_string('%*0$s', 'Hello');
0094 -- select format_string('%1$', 1);
0095 -- select format_string('%1$1', 1);
0096 -- check mix of positional and ordered placeholders
0097 select format_string('Hello %s %1$s %s', 'World', 'Hello again');
0098 select format_string('Hello %s %s, %2$s %2$s', 'World', 'Hello again');
0099 -- Skip these tests because Spark does not support variadic labeled argument
0100 -- check variadic labeled arguments
0101 -- select format('%s, %s', variadic array['Hello','World']);
0102 -- select format('%s, %s', variadic array[1, 2]);
0103 -- select format('%s, %s', variadic array[true, false]);
0104 -- select format('%s, %s', variadic array[true, false]::text[]);
0105 -- check variadic with positional placeholders
0106 -- select format('%2$s, %1$s', variadic array['first', 'second']);
0107 -- select format('%2$s, %1$s', variadic array[1, 2]);
0108 -- variadic argument can be array type NULL, but should not be referenced
0109 -- select format('Hello', variadic NULL::int[]);
0110 -- variadic argument allows simulating more than FUNC_MAX_ARGS parameters
0111 -- select format(string_agg('%s',','), variadic array_agg(i))
0112 -- from generate_series(1,200) g(i);
0113 -- check field widths and left, right alignment
0114 select format_string('>>%10s<<', 'Hello');
0115 select format_string('>>%10s<<', NULL);
0116 select format_string('>>%10s<<', '');
0117 select format_string('>>%-10s<<', '');
0118 select format_string('>>%-10s<<', 'Hello');
0119 select format_string('>>%-10s<<', NULL);
0120 select format_string('>>%1$10s<<', 'Hello');
0121 -- [SPARK-27930] format_string can not fully support PostgreSQL's format
0122 -- select format_string('>>%1$-10I<<', 'Hello');
0123 -- select format_string('>>%2$*1$L<<', 10, 'Hello');
0124 -- select format_string('>>%2$*1$L<<', 10, NULL);
0125 -- select format_string('>>%2$*1$L<<', -10, NULL);
0126 -- select format_string('>>%*s<<', 10, 'Hello');
0127 -- select format_string('>>%*1$s<<', 10, 'Hello');
0128 -- select format_string('>>%-s<<', 'Hello');
0129 -- select format_string('>>%10L<<', NULL);
0130 -- select format_string('>>%2$*1$L<<', NULL, 'Hello');
0131 -- select format_string('>>%2$*1$L<<', 0, 'Hello');
0132 
0133 DROP TABLE TEXT_TBL;