]> granicus.if.org Git - postgresql/blob - src/test/regress/sql/text.sql
Add string functions: concat(), concat_ws(), left(), right(), and reverse().
[postgresql] / src / test / regress / sql / text.sql
1 --
2 -- TEXT
3 --
4
5 SELECT text 'this is a text string' = text 'this is a text string' AS true;
6
7 SELECT text 'this is a text string' = text 'this is a text strin' AS false;
8
9 CREATE TABLE TEXT_TBL (f1 text);
10
11 INSERT INTO TEXT_TBL VALUES ('doh!');
12 INSERT INTO TEXT_TBL VALUES ('hi de ho neighbor');
13
14 SELECT '' AS two, * FROM TEXT_TBL;
15
16 -- As of 8.3 we have removed most implicit casts to text, so that for example
17 -- this no longer works:
18
19 select length(42);
20
21 -- But as a special exception for usability's sake, we still allow implicit
22 -- casting to text in concatenations, so long as the other input is text or
23 -- an unknown literal.  So these work:
24
25 select 'four: '::text || 2+2;
26 select 'four: ' || 2+2;
27
28 -- but not this:
29
30 select 3 || 4.0;
31
32 /*
33  * string functions
34  */
35 select concat('one');
36 select concat(1,2,3,'hello',true, false, to_date('20100309','YYYYMMDD'));
37 select concat_ws('#','one');
38 select concat_ws('#',1,2,3,'hello',true, false, to_date('20100309','YYYYMMDD'));
39 select concat_ws(',',10,20,null,30);
40 select concat_ws('',10,20,null,30);
41 select concat_ws(NULL,10,20,null,30) is null;
42 select reverse('abcde');
43 select i, left('ahoj', i), right('ahoj', i) from generate_series(-5, 5) t(i) order by i;