1--
2-- STRINGS
3-- Test various data entry syntaxes.
4--
5
6-- SQL string continuation syntax
7-- E021-03 character string literals
8SELECT 'first line'
9' - next line'
10	' - third line'
11	AS "Three lines to one";
12
13-- illegal string continuation syntax
14SELECT 'first line'
15' - next line' /* this comment is not allowed here */
16' - third line'
17	AS "Illegal comment within continuation";
18
19-- Unicode escapes
20SET standard_conforming_strings TO on;
21
22SELECT U&'d\0061t\+000061' AS U&"d\0061t\+000061";
23SELECT U&'d!0061t\+000061' UESCAPE '!' AS U&"d*0061t\+000061" UESCAPE '*';
24
25SELECT U&' \' UESCAPE '!' AS "tricky";
26SELECT 'tricky' AS U&"\" UESCAPE '!';
27
28SELECT U&'wrong: \061';
29SELECT U&'wrong: \+0061';
30SELECT U&'wrong: +0061' UESCAPE '+';
31
32SET standard_conforming_strings TO off;
33
34SELECT U&'d\0061t\+000061' AS U&"d\0061t\+000061";
35SELECT U&'d!0061t\+000061' UESCAPE '!' AS U&"d*0061t\+000061" UESCAPE '*';
36
37SELECT U&' \' UESCAPE '!' AS "tricky";
38SELECT 'tricky' AS U&"\" UESCAPE '!';
39
40SELECT U&'wrong: \061';
41SELECT U&'wrong: \+0061';
42SELECT U&'wrong: +0061' UESCAPE '+';
43
44RESET standard_conforming_strings;
45
46-- bytea
47SET bytea_output TO hex;
48SELECT E'\\xDeAdBeEf'::bytea;
49SELECT E'\\x De Ad Be Ef '::bytea;
50SELECT E'\\xDeAdBeE'::bytea;
51SELECT E'\\xDeAdBeEx'::bytea;
52SELECT E'\\xDe00BeEf'::bytea;
53SELECT E'DeAdBeEf'::bytea;
54SELECT E'De\\000dBeEf'::bytea;
55SELECT E'De\123dBeEf'::bytea;
56SELECT E'De\\123dBeEf'::bytea;
57SELECT E'De\\678dBeEf'::bytea;
58
59SET bytea_output TO escape;
60SELECT E'\\xDeAdBeEf'::bytea;
61SELECT E'\\x De Ad Be Ef '::bytea;
62SELECT E'\\xDe00BeEf'::bytea;
63SELECT E'DeAdBeEf'::bytea;
64SELECT E'De\\000dBeEf'::bytea;
65SELECT E'De\\123dBeEf'::bytea;
66
67--
68-- test conversions between various string types
69-- E021-10 implicit casting among the character data types
70--
71
72SELECT CAST(f1 AS text) AS "text(char)" FROM CHAR_TBL;
73
74SELECT CAST(f1 AS text) AS "text(varchar)" FROM VARCHAR_TBL;
75
76SELECT CAST(name 'namefield' AS text) AS "text(name)";
77
78-- since this is an explicit cast, it should truncate w/o error:
79SELECT CAST(f1 AS char(10)) AS "char(text)" FROM TEXT_TBL;
80-- note: implicit-cast case is tested in char.sql
81
82SELECT CAST(f1 AS char(20)) AS "char(text)" FROM TEXT_TBL;
83
84SELECT CAST(f1 AS char(10)) AS "char(varchar)" FROM VARCHAR_TBL;
85
86SELECT CAST(name 'namefield' AS char(10)) AS "char(name)";
87
88SELECT CAST(f1 AS varchar) AS "varchar(text)" FROM TEXT_TBL;
89
90SELECT CAST(f1 AS varchar) AS "varchar(char)" FROM CHAR_TBL;
91
92SELECT CAST(name 'namefield' AS varchar) AS "varchar(name)";
93
94--
95-- test SQL string functions
96-- E### and T### are feature reference numbers from SQL99
97--
98
99-- E021-09 trim function
100SELECT TRIM(BOTH FROM '  bunch o blanks  ') = 'bunch o blanks' AS "bunch o blanks";
101
102SELECT TRIM(LEADING FROM '  bunch o blanks  ') = 'bunch o blanks  ' AS "bunch o blanks  ";
103
104SELECT TRIM(TRAILING FROM '  bunch o blanks  ') = '  bunch o blanks' AS "  bunch o blanks";
105
106SELECT TRIM(BOTH 'x' FROM 'xxxxxsome Xsxxxxx') = 'some Xs' AS "some Xs";
107
108-- E021-06 substring expression
109SELECT SUBSTRING('1234567890' FROM 3) = '34567890' AS "34567890";
110
111SELECT SUBSTRING('1234567890' FROM 4 FOR 3) = '456' AS "456";
112
113-- T581 regular expression substring (with SQL99's bizarre regexp syntax)
114SELECT SUBSTRING('abcdefg' FROM 'a#"(b_d)#"%' FOR '#') AS "bcd";
115
116-- No match should return NULL
117SELECT SUBSTRING('abcdefg' FROM '#"(b_d)#"%' FOR '#') IS NULL AS "True";
118
119-- Null inputs should return NULL
120SELECT SUBSTRING('abcdefg' FROM '(b|c)' FOR NULL) IS NULL AS "True";
121SELECT SUBSTRING(NULL FROM '(b|c)' FOR '#') IS NULL AS "True";
122SELECT SUBSTRING('abcdefg' FROM NULL FOR '#') IS NULL AS "True";
123
124-- PostgreSQL extension to allow omitting the escape character;
125-- here the regexp is taken as Posix syntax
126SELECT SUBSTRING('abcdefg' FROM 'c.e') AS "cde";
127
128-- With a parenthesized subexpression, return only what matches the subexpr
129SELECT SUBSTRING('abcdefg' FROM 'b(.*)f') AS "cde";
130
131-- PostgreSQL extension to allow using back reference in replace string;
132SELECT regexp_replace('1112223333', E'(\\d{3})(\\d{3})(\\d{4})', E'(\\1) \\2-\\3');
133SELECT regexp_replace('AAA   BBB   CCC   ', E'\\s+', ' ', 'g');
134SELECT regexp_replace('AAA', '^|$', 'Z', 'g');
135SELECT regexp_replace('AAA aaa', 'A+', 'Z', 'gi');
136-- invalid regexp option
137SELECT regexp_replace('AAA aaa', 'A+', 'Z', 'z');
138
139-- set so we can tell NULL from empty string
140\pset null '\\N'
141
142-- return all matches from regexp
143SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque)$re$);
144
145-- test case insensitive
146SELECT regexp_matches('foObARbEqUEbAz', $re$(bar)(beque)$re$, 'i');
147
148-- global option - more than one match
149SELECT regexp_matches('foobarbequebazilbarfbonk', $re$(b[^b]+)(b[^b]+)$re$, 'g');
150
151-- empty capture group (matched empty string)
152SELECT regexp_matches('foobarbequebaz', $re$(bar)(.*)(beque)$re$);
153-- no match
154SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)(beque)$re$);
155-- optional capture group did not match, null entry in array
156SELECT regexp_matches('foobarbequebaz', $re$(bar)(.+)?(beque)$re$);
157
158-- no capture groups
159SELECT regexp_matches('foobarbequebaz', $re$barbeque$re$);
160
161-- start/end-of-line matches are of zero length
162SELECT regexp_matches('foo' || chr(10) || 'bar' || chr(10) || 'bequq' || chr(10) || 'baz', '^', 'mg');
163SELECT regexp_matches('foo' || chr(10) || 'bar' || chr(10) || 'bequq' || chr(10) || 'baz', '$', 'mg');
164SELECT regexp_matches('1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4' || chr(10), '^.?', 'mg');
165SELECT regexp_matches(chr(10) || '1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4' || chr(10), '.?$', 'mg');
166SELECT regexp_matches(chr(10) || '1' || chr(10) || '2' || chr(10) || '3' || chr(10) || '4', '.?$', 'mg');
167
168-- give me errors
169SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque)$re$, 'gz');
170SELECT regexp_matches('foobarbequebaz', $re$(barbeque$re$);
171SELECT regexp_matches('foobarbequebaz', $re$(bar)(beque){2,1}$re$);
172
173-- split string on regexp
174SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', $re$\s+$re$) AS foo;
175SELECT regexp_split_to_array('the quick brown fox jumps over the lazy dog', $re$\s+$re$);
176
177SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', $re$\s*$re$) AS foo;
178SELECT regexp_split_to_array('the quick brown fox jumps over the lazy dog', $re$\s*$re$);
179SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', '') AS foo;
180SELECT regexp_split_to_array('the quick brown fox jumps over the lazy dog', '');
181-- case insensitive
182SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'i') AS foo;
183SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'i');
184-- no match of pattern
185SELECT foo, length(foo) FROM regexp_split_to_table('the quick brown fox jumps over the lazy dog', 'nomatch') AS foo;
186SELECT regexp_split_to_array('the quick brown fox jumps over the lazy dog', 'nomatch');
187-- some corner cases
188SELECT regexp_split_to_array('123456','1');
189SELECT regexp_split_to_array('123456','6');
190SELECT regexp_split_to_array('123456','.');
191SELECT regexp_split_to_array('123456','');
192SELECT regexp_split_to_array('123456','(?:)');
193SELECT regexp_split_to_array('1','');
194-- errors
195SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'zippy') AS foo;
196SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'iz');
197-- global option meaningless for regexp_split
198SELECT foo, length(foo) FROM regexp_split_to_table('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'g') AS foo;
199SELECT regexp_split_to_array('thE QUick bROWn FOx jUMPs ovEr The lazy dOG', 'e', 'g');
200
201-- change NULL-display back
202\pset null ''
203
204-- E021-11 position expression
205SELECT POSITION('4' IN '1234567890') = '4' AS "4";
206
207SELECT POSITION('5' IN '1234567890') = '5' AS "5";
208
209-- T312 character overlay function
210SELECT OVERLAY('abcdef' PLACING '45' FROM 4) AS "abc45f";
211
212SELECT OVERLAY('yabadoo' PLACING 'daba' FROM 5) AS "yabadaba";
213
214SELECT OVERLAY('yabadoo' PLACING 'daba' FROM 5 FOR 0) AS "yabadabadoo";
215
216SELECT OVERLAY('babosa' PLACING 'ubb' FROM 2 FOR 4) AS "bubba";
217
218--
219-- test LIKE
220-- Be sure to form every test as a LIKE/NOT LIKE pair.
221--
222
223-- simplest examples
224-- E061-04 like predicate
225SELECT 'hawkeye' LIKE 'h%' AS "true";
226SELECT 'hawkeye' NOT LIKE 'h%' AS "false";
227
228SELECT 'hawkeye' LIKE 'H%' AS "false";
229SELECT 'hawkeye' NOT LIKE 'H%' AS "true";
230
231SELECT 'hawkeye' LIKE 'indio%' AS "false";
232SELECT 'hawkeye' NOT LIKE 'indio%' AS "true";
233
234SELECT 'hawkeye' LIKE 'h%eye' AS "true";
235SELECT 'hawkeye' NOT LIKE 'h%eye' AS "false";
236
237SELECT 'indio' LIKE '_ndio' AS "true";
238SELECT 'indio' NOT LIKE '_ndio' AS "false";
239
240SELECT 'indio' LIKE 'in__o' AS "true";
241SELECT 'indio' NOT LIKE 'in__o' AS "false";
242
243SELECT 'indio' LIKE 'in_o' AS "false";
244SELECT 'indio' NOT LIKE 'in_o' AS "true";
245
246-- unused escape character
247SELECT 'hawkeye' LIKE 'h%' ESCAPE '#' AS "true";
248SELECT 'hawkeye' NOT LIKE 'h%' ESCAPE '#' AS "false";
249
250SELECT 'indio' LIKE 'ind_o' ESCAPE '$' AS "true";
251SELECT 'indio' NOT LIKE 'ind_o' ESCAPE '$' AS "false";
252
253-- escape character
254-- E061-05 like predicate with escape clause
255SELECT 'h%' LIKE 'h#%' ESCAPE '#' AS "true";
256SELECT 'h%' NOT LIKE 'h#%' ESCAPE '#' AS "false";
257
258SELECT 'h%wkeye' LIKE 'h#%' ESCAPE '#' AS "false";
259SELECT 'h%wkeye' NOT LIKE 'h#%' ESCAPE '#' AS "true";
260
261SELECT 'h%wkeye' LIKE 'h#%%' ESCAPE '#' AS "true";
262SELECT 'h%wkeye' NOT LIKE 'h#%%' ESCAPE '#' AS "false";
263
264SELECT 'h%awkeye' LIKE 'h#%a%k%e' ESCAPE '#' AS "true";
265SELECT 'h%awkeye' NOT LIKE 'h#%a%k%e' ESCAPE '#' AS "false";
266
267SELECT 'indio' LIKE '_ndio' ESCAPE '$' AS "true";
268SELECT 'indio' NOT LIKE '_ndio' ESCAPE '$' AS "false";
269
270SELECT 'i_dio' LIKE 'i$_d_o' ESCAPE '$' AS "true";
271SELECT 'i_dio' NOT LIKE 'i$_d_o' ESCAPE '$' AS "false";
272
273SELECT 'i_dio' LIKE 'i$_nd_o' ESCAPE '$' AS "false";
274SELECT 'i_dio' NOT LIKE 'i$_nd_o' ESCAPE '$' AS "true";
275
276SELECT 'i_dio' LIKE 'i$_d%o' ESCAPE '$' AS "true";
277SELECT 'i_dio' NOT LIKE 'i$_d%o' ESCAPE '$' AS "false";
278
279-- escape character same as pattern character
280SELECT 'maca' LIKE 'm%aca' ESCAPE '%' AS "true";
281SELECT 'maca' NOT LIKE 'm%aca' ESCAPE '%' AS "false";
282
283SELECT 'ma%a' LIKE 'm%a%%a' ESCAPE '%' AS "true";
284SELECT 'ma%a' NOT LIKE 'm%a%%a' ESCAPE '%' AS "false";
285
286SELECT 'bear' LIKE 'b_ear' ESCAPE '_' AS "true";
287SELECT 'bear' NOT LIKE 'b_ear' ESCAPE '_' AS "false";
288
289SELECT 'be_r' LIKE 'b_e__r' ESCAPE '_' AS "true";
290SELECT 'be_r' NOT LIKE 'b_e__r' ESCAPE '_' AS "false";
291
292SELECT 'be_r' LIKE '__e__r' ESCAPE '_' AS "false";
293SELECT 'be_r' NOT LIKE '__e__r' ESCAPE '_' AS "true";
294
295
296--
297-- test ILIKE (case-insensitive LIKE)
298-- Be sure to form every test as an ILIKE/NOT ILIKE pair.
299--
300
301SELECT 'hawkeye' ILIKE 'h%' AS "true";
302SELECT 'hawkeye' NOT ILIKE 'h%' AS "false";
303
304SELECT 'hawkeye' ILIKE 'H%' AS "true";
305SELECT 'hawkeye' NOT ILIKE 'H%' AS "false";
306
307SELECT 'hawkeye' ILIKE 'H%Eye' AS "true";
308SELECT 'hawkeye' NOT ILIKE 'H%Eye' AS "false";
309
310SELECT 'Hawkeye' ILIKE 'h%' AS "true";
311SELECT 'Hawkeye' NOT ILIKE 'h%' AS "false";
312
313--
314-- test %/_ combination cases, cf bugs #4821 and #5478
315--
316
317SELECT 'foo' LIKE '_%' as t, 'f' LIKE '_%' as t, '' LIKE '_%' as f;
318SELECT 'foo' LIKE '%_' as t, 'f' LIKE '%_' as t, '' LIKE '%_' as f;
319
320SELECT 'foo' LIKE '__%' as t, 'foo' LIKE '___%' as t, 'foo' LIKE '____%' as f;
321SELECT 'foo' LIKE '%__' as t, 'foo' LIKE '%___' as t, 'foo' LIKE '%____' as f;
322
323SELECT 'jack' LIKE '%____%' AS t;
324
325
326--
327-- basic tests of LIKE with indexes
328--
329
330CREATE TABLE texttest (a text PRIMARY KEY, b int);
331SELECT * FROM texttest WHERE a LIKE '%1%';
332
333CREATE TABLE byteatest (a bytea PRIMARY KEY, b int);
334SELECT * FROM byteatest WHERE a LIKE '%1%';
335
336DROP TABLE texttest, byteatest;
337
338
339--
340-- test implicit type conversion
341--
342
343-- E021-07 character concatenation
344SELECT 'unknown' || ' and unknown' AS "Concat unknown types";
345
346SELECT text 'text' || ' and unknown' AS "Concat text to unknown type";
347
348SELECT char(20) 'characters' || ' and text' AS "Concat char to unknown type";
349
350SELECT text 'text' || char(20) ' and characters' AS "Concat text to char";
351
352SELECT text 'text' || varchar ' and varchar' AS "Concat text to varchar";
353
354--
355-- test substr with toasted text values
356--
357CREATE TABLE toasttest(f1 text);
358
359insert into toasttest values(repeat('1234567890',10000));
360insert into toasttest values(repeat('1234567890',10000));
361
362--
363-- Ensure that some values are uncompressed, to test the faster substring
364-- operation used in that case
365--
366alter table toasttest alter column f1 set storage external;
367insert into toasttest values(repeat('1234567890',10000));
368insert into toasttest values(repeat('1234567890',10000));
369
370-- If the starting position is zero or less, then return from the start of the string
371-- adjusting the length to be consistent with the "negative start" per SQL.
372SELECT substr(f1, -1, 5) from toasttest;
373
374-- If the length is less than zero, an ERROR is thrown.
375SELECT substr(f1, 5, -1) from toasttest;
376
377-- If no third argument (length) is provided, the length to the end of the
378-- string is assumed.
379SELECT substr(f1, 99995) from toasttest;
380
381-- If start plus length is > string length, the result is truncated to
382-- string length
383SELECT substr(f1, 99995, 10) from toasttest;
384
385TRUNCATE TABLE toasttest;
386INSERT INTO toasttest values (repeat('1234567890',300));
387INSERT INTO toasttest values (repeat('1234567890',300));
388INSERT INTO toasttest values (repeat('1234567890',300));
389INSERT INTO toasttest values (repeat('1234567890',300));
390-- expect >0 blocks
391SELECT pg_relation_size(reltoastrelid) = 0 AS is_empty
392  FROM pg_class where relname = 'toasttest';
393
394TRUNCATE TABLE toasttest;
395ALTER TABLE toasttest set (toast_tuple_target = 4080);
396INSERT INTO toasttest values (repeat('1234567890',300));
397INSERT INTO toasttest values (repeat('1234567890',300));
398INSERT INTO toasttest values (repeat('1234567890',300));
399INSERT INTO toasttest values (repeat('1234567890',300));
400-- expect 0 blocks
401SELECT pg_relation_size(reltoastrelid) = 0 AS is_empty
402  FROM pg_class where relname = 'toasttest';
403
404DROP TABLE toasttest;
405
406--
407-- test substr with toasted bytea values
408--
409CREATE TABLE toasttest(f1 bytea);
410
411insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
412insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
413
414--
415-- Ensure that some values are uncompressed, to test the faster substring
416-- operation used in that case
417--
418alter table toasttest alter column f1 set storage external;
419insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
420insert into toasttest values(decode(repeat('1234567890',10000),'escape'));
421
422-- If the starting position is zero or less, then return from the start of the string
423-- adjusting the length to be consistent with the "negative start" per SQL.
424SELECT substr(f1, -1, 5) from toasttest;
425
426-- If the length is less than zero, an ERROR is thrown.
427SELECT substr(f1, 5, -1) from toasttest;
428
429-- If no third argument (length) is provided, the length to the end of the
430-- string is assumed.
431SELECT substr(f1, 99995) from toasttest;
432
433-- If start plus length is > string length, the result is truncated to
434-- string length
435SELECT substr(f1, 99995, 10) from toasttest;
436
437DROP TABLE toasttest;
438
439-- test internally compressing datums
440
441-- this tests compressing a datum to a very small size which exercises a
442-- corner case in packed-varlena handling: even though small, the compressed
443-- datum must be given a 4-byte header because there are no bits to indicate
444-- compression in a 1-byte header
445
446CREATE TABLE toasttest (c char(4096));
447INSERT INTO toasttest VALUES('x');
448SELECT length(c), c::text FROM toasttest;
449SELECT c FROM toasttest;
450DROP TABLE toasttest;
451
452--
453-- test length
454--
455
456SELECT length('abcdef') AS "length_6";
457
458--
459-- test strpos
460--
461
462SELECT strpos('abcdef', 'cd') AS "pos_3";
463
464SELECT strpos('abcdef', 'xy') AS "pos_0";
465
466--
467-- test replace
468--
469SELECT replace('abcdef', 'de', '45') AS "abc45f";
470
471SELECT replace('yabadabadoo', 'ba', '123') AS "ya123da123doo";
472
473SELECT replace('yabadoo', 'bad', '') AS "yaoo";
474
475--
476-- test split_part
477--
478select split_part('joeuser@mydatabase','@',0) AS "an error";
479
480select split_part('joeuser@mydatabase','@',1) AS "joeuser";
481
482select split_part('joeuser@mydatabase','@',2) AS "mydatabase";
483
484select split_part('joeuser@mydatabase','@',3) AS "empty string";
485
486select split_part('@joeuser@mydatabase@','@',2) AS "joeuser";
487
488--
489-- test to_hex
490--
491select to_hex(256*256*256 - 1) AS "ffffff";
492
493select to_hex(256::bigint*256::bigint*256::bigint*256::bigint - 1) AS "ffffffff";
494
495--
496-- MD5 test suite - from IETF RFC 1321
497-- (see: ftp://ftp.rfc-editor.org/in-notes/rfc1321.txt)
498--
499select md5('') = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE";
500
501select md5('a') = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";
502
503select md5('abc') = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";
504
505select md5('message digest') = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";
506
507select md5('abcdefghijklmnopqrstuvwxyz') = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";
508
509select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";
510
511select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890') = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";
512
513select md5(''::bytea) = 'd41d8cd98f00b204e9800998ecf8427e' AS "TRUE";
514
515select md5('a'::bytea) = '0cc175b9c0f1b6a831c399e269772661' AS "TRUE";
516
517select md5('abc'::bytea) = '900150983cd24fb0d6963f7d28e17f72' AS "TRUE";
518
519select md5('message digest'::bytea) = 'f96b697d7cb7938d525a2f31aaf161d0' AS "TRUE";
520
521select md5('abcdefghijklmnopqrstuvwxyz'::bytea) = 'c3fcd3d76192e4007dfb496cca67e13b' AS "TRUE";
522
523select md5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'::bytea) = 'd174ab98d277d9f5a5611c2c9f419d9f' AS "TRUE";
524
525select md5('12345678901234567890123456789012345678901234567890123456789012345678901234567890'::bytea) = '57edf4a22be3c955ac49da2e2107b67a' AS "TRUE";
526
527--
528-- SHA-2
529--
530SET bytea_output TO hex;
531
532SELECT sha224('');
533SELECT sha224('The quick brown fox jumps over the lazy dog.');
534
535SELECT sha256('');
536SELECT sha256('The quick brown fox jumps over the lazy dog.');
537
538SELECT sha384('');
539SELECT sha384('The quick brown fox jumps over the lazy dog.');
540
541SELECT sha512('');
542SELECT sha512('The quick brown fox jumps over the lazy dog.');
543
544--
545-- test behavior of escape_string_warning and standard_conforming_strings options
546--
547set escape_string_warning = off;
548set standard_conforming_strings = off;
549
550show escape_string_warning;
551show standard_conforming_strings;
552
553set escape_string_warning = on;
554set standard_conforming_strings = on;
555
556show escape_string_warning;
557show standard_conforming_strings;
558
559select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\'   as f4, 'ab\''cd' as f5, '\\' as f6;
560
561set standard_conforming_strings = off;
562
563select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\'   as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
564
565set escape_string_warning = off;
566set standard_conforming_strings = on;
567
568select 'a\bcd' as f1, 'a\b''cd' as f2, 'a\b''''cd' as f3, 'abcd\'   as f4, 'ab\''cd' as f5, '\\' as f6;
569
570set standard_conforming_strings = off;
571
572select 'a\\bcd' as f1, 'a\\b\'cd' as f2, 'a\\b\'''cd' as f3, 'abcd\\'   as f4, 'ab\\\'cd' as f5, '\\\\' as f6;
573
574
575--
576-- Additional string functions
577--
578SET bytea_output TO escape;
579
580SELECT initcap('hi THOMAS');
581
582SELECT lpad('hi', 5, 'xy');
583SELECT lpad('hi', 5);
584SELECT lpad('hi', -5, 'xy');
585SELECT lpad('hello', 2);
586SELECT lpad('hi', 5, '');
587
588SELECT rpad('hi', 5, 'xy');
589SELECT rpad('hi', 5);
590SELECT rpad('hi', -5, 'xy');
591SELECT rpad('hello', 2);
592SELECT rpad('hi', 5, '');
593
594SELECT ltrim('zzzytrim', 'xyz');
595
596SELECT translate('', '14', 'ax');
597SELECT translate('12345', '14', 'ax');
598
599SELECT ascii('x');
600SELECT ascii('');
601
602SELECT chr(65);
603SELECT chr(0);
604
605SELECT repeat('Pg', 4);
606SELECT repeat('Pg', -4);
607
608SELECT trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea);
609SELECT btrim(E'\\000trim\\000'::bytea, E'\\000'::bytea);
610SELECT btrim(''::bytea, E'\\000'::bytea);
611SELECT btrim(E'\\000trim\\000'::bytea, ''::bytea);
612SELECT encode(overlay(E'Th\\000omas'::bytea placing E'Th\\001omas'::bytea from 2),'escape');
613SELECT encode(overlay(E'Th\\000omas'::bytea placing E'\\002\\003'::bytea from 8),'escape');
614SELECT encode(overlay(E'Th\\000omas'::bytea placing E'\\002\\003'::bytea from 5 for 3),'escape');
615