OSDN Git Service

b84e8544d5e084696b838f9b3199e6d817992f10
[pg-rex/syncrep.git] / src / test / regress / expected / text.out
1 --
2 -- TEXT
3 --
4 SELECT text 'this is a text string' = text 'this is a text string' AS true;
5  true 
6 ------
7  t
8 (1 row)
9
10 SELECT text 'this is a text string' = text 'this is a text strin' AS false;
11  false 
12 -------
13  f
14 (1 row)
15
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;
20  two |        f1         
21 -----+-------------------
22      | doh!
23      | hi de ho neighbor
24 (2 rows)
25
26 -- As of 8.3 we have removed most implicit casts to text, so that for example
27 -- this no longer works:
28 select length(42);
29 ERROR:  function length(integer) does not exist
30 LINE 1: select length(42);
31                ^
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;
37  ?column? 
38 ----------
39  four: 4
40 (1 row)
41
42 select 'four: ' || 2+2;
43  ?column? 
44 ----------
45  four: 4
46 (1 row)
47
48 -- but not this:
49 select 3 || 4.0;
50 ERROR:  operator does not exist: integer || numeric
51 LINE 1: select 3 || 4.0;
52                  ^
53 HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
54 /*
55  * various string functions
56  */
57 select concat('one');
58  concat 
59 --------
60  one
61 (1 row)
62
63 select concat(1,2,3,'hello',true, false, to_date('20100309','YYYYMMDD'));
64         concat        
65 ----------------------
66  123hellotf03-09-2010
67 (1 row)
68
69 select concat_ws('#','one');
70  concat_ws 
71 -----------
72  one
73 (1 row)
74
75 select concat_ws('#',1,2,3,'hello',true, false, to_date('20100309','YYYYMMDD'));
76          concat_ws          
77 ----------------------------
78  1#2#3#hello#t#f#03-09-2010
79 (1 row)
80
81 select concat_ws(',',10,20,null,30);
82  concat_ws 
83 -----------
84  10,20,30
85 (1 row)
86
87 select concat_ws('',10,20,null,30);
88  concat_ws 
89 -----------
90  102030
91 (1 row)
92
93 select concat_ws(NULL,10,20,null,30) is null;
94  ?column? 
95 ----------
96  t
97 (1 row)
98
99 select reverse('abcde');
100  reverse 
101 ---------
102  edcba
103 (1 row)
104
105 select i, left('ahoj', i), right('ahoj', i) from generate_series(-5, 5) t(i) order by i;
106  i  | left | right 
107 ----+------+-------
108  -5 |      | 
109  -4 |      | 
110  -3 | a    | j
111  -2 | ah   | oj
112  -1 | aho  | hoj
113   0 |      | 
114   1 | a    | j
115   2 | ah   | oj
116   3 | aho  | hoj
117   4 | ahoj | ahoj
118   5 | ahoj | ahoj
119 (11 rows)
120
121 select quote_literal('');
122  quote_literal 
123 ---------------
124  ''
125 (1 row)
126
127 select quote_literal('abc''');
128  quote_literal 
129 ---------------
130  'abc'''
131 (1 row)
132
133 select quote_literal(e'\\');
134  quote_literal 
135 ---------------
136  E'\\'
137 (1 row)
138
139 /*
140  * format
141  */
142 select format(NULL);
143  format 
144 --------
145  
146 (1 row)
147
148 select format('Hello');
149  format 
150 --------
151  Hello
152 (1 row)
153
154 select format('Hello %s', 'World');
155    format    
156 -------------
157  Hello World
158 (1 row)
159
160 select format('Hello %%');
161  format  
162 ---------
163  Hello %
164 (1 row)
165
166 select format('Hello %%%%');
167   format  
168 ----------
169  Hello %%
170 (1 row)
171
172 -- should fail
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');
181                  format                 
182 ----------------------------------------
183  INSERT INTO mytab VALUES('10','Hello')
184 (1 row)
185
186 select format('%s%s%s','Hello', NULL,'World');
187    format   
188 ------------
189  HelloWorld
190 (1 row)
191
192 select format('INSERT INTO %I VALUES(%L,%L)', 'mytab', 10, NULL);
193                format                
194 -------------------------------------
195  INSERT INTO mytab VALUES('10',NULL)
196 (1 row)
197
198 select format('INSERT INTO %I VALUES(%L,%L)', 'mytab', NULL, 'Hello');
199                  format                 
200 ----------------------------------------
201  INSERT INTO mytab VALUES(NULL,'Hello')
202 (1 row)
203
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);
209  format 
210 --------
211  1 3
212 (1 row)
213
214 select format('%1$s %12$s', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
215  format 
216 --------
217  1 12
218 (1 row)
219
220 -- should fail
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');
233             format             
234 -------------------------------
235  Hello World World Hello again
236 (1 row)
237
238 select format('Hello %s %s, %2$s %2$s', 'World', 'Hello again');
239                       format                      
240 --------------------------------------------------
241  Hello World Hello again, Hello again Hello again
242 (1 row)
243