4 SELECT text 'this is a text string' = text 'this is a text string' AS true;
10 SELECT text 'this is a text string' = text 'this is a text strin' AS false;
16 CREATE TABLE TEXT_TBL (f1 text);
17 INSERT INTO TEXT_TBL VALUES ('doh!');
18 INSERT INTO TEXT_TBL VALUES ('hi de ho neighbor');
19 SELECT '' AS two, * FROM TEXT_TBL;
21 -----+-------------------
26 -- As of 8.3 we have removed most implicit casts to text, so that for example
27 -- this no longer works:
29 ERROR: function length(integer) does not exist
30 LINE 1: select length(42);
32 HINT: No function matches the given name and argument types. You might need to add explicit type casts.
33 -- But as a special exception for usability's sake, we still allow implicit
34 -- casting to text in concatenations, so long as the other input is text or
35 -- an unknown literal. So these work:
36 select 'four: '::text || 2+2;
42 select 'four: ' || 2+2;
50 ERROR: operator does not exist: integer || numeric
51 LINE 1: select 3 || 4.0;
53 HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
55 * various string functions
63 select concat(1,2,3,'hello',true, false, to_date('20100309','YYYYMMDD'));
65 ----------------------
69 select concat_ws('#','one');
75 select concat_ws('#',1,2,3,'hello',true, false, to_date('20100309','YYYYMMDD'));
77 ----------------------------
78 1#2#3#hello#t#f#03-09-2010
81 select concat_ws(',',10,20,null,30);
87 select concat_ws('',10,20,null,30);
93 select concat_ws(NULL,10,20,null,30) is null;
99 select reverse('abcde');
105 select i, left('ahoj', i), right('ahoj', i) from generate_series(-5, 5) t(i) order by i;
121 select quote_literal('');
127 select quote_literal('abc''');
133 select quote_literal(e'\\');
148 select format('Hello');
154 select format('Hello %s', 'World');
160 select format('Hello %%');
166 select format('Hello %%%%');
173 select format('Hello %s %s', 'World');
174 ERROR: too few arguments for format conversion
175 select format('Hello %s');
176 ERROR: too few arguments for format conversion
177 select format('Hello %x', 20);
178 ERROR: unrecognized conversion specifier: x
179 -- check literal and sql identifiers
180 select format('INSERT INTO %I VALUES(%L,%L)', 'mytab', 10, 'Hello');
182 ----------------------------------------
183 INSERT INTO mytab VALUES('10','Hello')
186 select format('%s%s%s','Hello', NULL,'World');
192 select format('INSERT INTO %I VALUES(%L,%L)', 'mytab', 10, NULL);
194 -------------------------------------
195 INSERT INTO mytab VALUES('10',NULL)
198 select format('INSERT INTO %I VALUES(%L,%L)', 'mytab', NULL, 'Hello');
200 ----------------------------------------
201 INSERT INTO mytab VALUES(NULL,'Hello')
204 -- should fail, sql identifier cannot be NULL
205 select format('INSERT INTO %I VALUES(%L,%L)', NULL, 10, 'Hello');
206 ERROR: NULL cannot be escaped as an SQL identifier
207 -- check positional placeholders
208 select format('%1$s %3$s', 1, 2, 3);
214 select format('%1$s %12$s', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
221 select format('%1$s %4$s', 1, 2, 3);
222 ERROR: too few arguments for format conversion
223 select format('%1$s %13$s', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
224 ERROR: too few arguments for format conversion
225 select format('%1s', 1);
226 ERROR: unterminated conversion specifier
227 select format('%1$', 1);
228 ERROR: unterminated conversion specifier
229 select format('%1$1', 1);
230 ERROR: unrecognized conversion specifier: 1
231 --checkk mix of positional and ordered placeholders
232 select format('Hello %s %1$s %s', 'World', 'Hello again');
234 -------------------------------
235 Hello World World Hello again
238 select format('Hello %s %s, %2$s %2$s', 'World', 'Hello again');
240 --------------------------------------------------
241 Hello World Hello again, Hello again Hello again