~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/pl/plperl/test/test.expected

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
checkpoint;
 
2
CREATE OR REPLACE FUNCTION perl_int(int) RETURNS INTEGER AS $$
 
3
return undef;
 
4
$$ LANGUAGE plperl;
 
5
SELECT perl_int(11);
 
6
 perl_int 
 
7
----------
 
8
         
 
9
(1 row)
 
10
 
 
11
SELECT * FROM perl_int(42);
 
12
 perl_int 
 
13
----------
 
14
         
 
15
(1 row)
 
16
 
 
17
CREATE OR REPLACE FUNCTION perl_int(int) RETURNS INTEGER AS $$
 
18
return $_[0] + 1;
 
19
$$ LANGUAGE plperl;
 
20
SELECT perl_int(11);
 
21
 perl_int 
 
22
----------
 
23
       12
 
24
(1 row)
 
25
 
 
26
SELECT * FROM perl_int(42);
 
27
 perl_int 
 
28
----------
 
29
       43
 
30
(1 row)
 
31
 
 
32
CREATE OR REPLACE FUNCTION perl_set_int(int) RETURNS SETOF INTEGER AS $$
 
33
return undef;
 
34
$$ LANGUAGE plperl;
 
35
SELECT perl_set_int(5);
 
36
 perl_set_int 
 
37
--------------
 
38
(0 rows)
 
39
 
 
40
SELECT * FROM perl_set_int(5);
 
41
 perl_set_int 
 
42
--------------
 
43
(0 rows)
 
44
 
 
45
CREATE OR REPLACE FUNCTION perl_set_int(int) RETURNS SETOF INTEGER AS $$
 
46
return [0..$_[0]];
 
47
$$ LANGUAGE plperl;
 
48
SELECT perl_set_int(5);
 
49
 perl_set_int 
 
50
--------------
 
51
            0
 
52
            1
 
53
            2
 
54
            3
 
55
            4
 
56
            5
 
57
(6 rows)
 
58
 
 
59
SELECT * FROM perl_set_int(5);
 
60
 perl_set_int 
 
61
--------------
 
62
            0
 
63
            1
 
64
            2
 
65
            3
 
66
            4
 
67
            5
 
68
(6 rows)
 
69
 
 
70
CREATE TYPE testrowperl AS (f1 integer, f2 text, f3 text);
 
71
CREATE OR REPLACE FUNCTION perl_row() RETURNS testrowperl AS $$
 
72
    return undef;
 
73
$$ LANGUAGE plperl;
 
74
SELECT perl_row();
 
75
 perl_row 
 
76
----------
 
77
 
 
78
(1 row)
 
79
 
 
80
SELECT * FROM perl_row();
 
81
 f1 | f2 | f3 
 
82
----+----+----
 
83
    |    | 
 
84
(1 row)
 
85
 
 
86
CREATE OR REPLACE FUNCTION perl_row() RETURNS testrowperl AS $$
 
87
    return {f2 => 'hello', f1 => 1, f3 => 'world'};
 
88
$$ LANGUAGE plperl;
 
89
SELECT perl_row();
 
90
    perl_row     
 
91
-----------------
 
92
 (1,hello,world)
 
93
(1 row)
 
94
 
 
95
SELECT * FROM perl_row();
 
96
 f1 |  f2   |  f3   
 
97
----+-------+-------
 
98
  1 | hello | world
 
99
(1 row)
 
100
 
 
101
CREATE OR REPLACE FUNCTION perl_set() RETURNS SETOF testrowperl AS $$
 
102
    return undef;
 
103
$$  LANGUAGE plperl;
 
104
SELECT perl_set();
 
105
 perl_set 
 
106
----------
 
107
(0 rows)
 
108
 
 
109
SELECT * FROM perl_set();
 
110
 f1 | f2 | f3 
 
111
----+----+----
 
112
(0 rows)
 
113
 
 
114
CREATE OR REPLACE FUNCTION perl_set() RETURNS SETOF testrowperl AS $$
 
115
    return [
 
116
        { f1 => 1, f2 => 'Hello', f3 =>  'World' },
 
117
        undef,
 
118
        { f1 => 3, f2 => 'Hello', f3 =>  'PL/Perl' }
 
119
    ];
 
120
$$  LANGUAGE plperl;
 
121
SELECT perl_set();
 
122
ERROR:  elements of Perl result array must be reference to hash
 
123
SELECT * FROM perl_set();
 
124
ERROR:  elements of Perl result array must be reference to hash
 
125
CREATE OR REPLACE FUNCTION perl_set() RETURNS SETOF testrowperl AS $$
 
126
    return [
 
127
        { f1 => 1, f2 => 'Hello', f3 =>  'World' },
 
128
        { f1 => 2, f2 => 'Hello', f3 =>  'PostgreSQL' },
 
129
        { f1 => 3, f2 => 'Hello', f3 =>  'PL/Perl' }
 
130
    ];
 
131
$$  LANGUAGE plperl;
 
132
SELECT perl_set();
 
133
       perl_set       
 
134
----------------------
 
135
 (1,Hello,World)
 
136
 (2,Hello,PostgreSQL)
 
137
 (3,Hello,PL/Perl)
 
138
(3 rows)
 
139
 
 
140
SELECT * FROM perl_set();
 
141
 f1 |  f2   |     f3     
 
142
----+-------+------------
 
143
  1 | Hello | World
 
144
  2 | Hello | PostgreSQL
 
145
  3 | Hello | PL/Perl
 
146
(3 rows)
 
147
 
 
148
CREATE OR REPLACE FUNCTION perl_record() RETURNS record AS $$
 
149
    return undef;
 
150
$$ LANGUAGE plperl;
 
151
SELECT perl_record();
 
152
 perl_record 
 
153
-------------
 
154
 
 
155
(1 row)
 
156
 
 
157
SELECT * FROM perl_record();
 
158
ERROR:  a column definition list is required for functions returning "record"
 
159
SELECT * FROM perl_record() AS (f1 integer, f2 text, f3 text);
 
160
 f1 | f2 | f3 
 
161
----+----+----
 
162
    |    | 
 
163
(1 row)
 
164
 
 
165
CREATE OR REPLACE FUNCTION perl_record() RETURNS record AS $$
 
166
    return {f2 => 'hello', f1 => 1, f3 => 'world'};
 
167
$$ LANGUAGE plperl;
 
168
SELECT perl_record();
 
169
ERROR:  function returning record called in context that cannot accept type record
 
170
SELECT * FROM perl_record();
 
171
ERROR:  a column definition list is required for functions returning "record"
 
172
SELECT * FROM perl_record() AS (f1 integer, f2 text, f3 text);
 
173
 f1 |  f2   |  f3   
 
174
----+-------+-------
 
175
  1 | hello | world
 
176
(1 row)
 
177
 
 
178
CREATE OR REPLACE FUNCTION perl_record_set() RETURNS SETOF record AS $$
 
179
    return undef;
 
180
$$  LANGUAGE plperl;
 
181
SELECT perl_record_set();
 
182
 perl_record_set 
 
183
-----------------
 
184
(0 rows)
 
185
 
 
186
SELECT * FROM perl_record_set();
 
187
ERROR:  a column definition list is required for functions returning "record"
 
188
SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
 
189
 f1 | f2 | f3 
 
190
----+----+----
 
191
(0 rows)
 
192
 
 
193
CREATE OR REPLACE FUNCTION perl_record_set() RETURNS SETOF record AS $$
 
194
    return [
 
195
        { f1 => 1, f2 => 'Hello', f3 =>  'World' },
 
196
        undef,
 
197
        { f1 => 3, f2 => 'Hello', f3 =>  'PL/Perl' }
 
198
    ];
 
199
$$  LANGUAGE plperl;
 
200
SELECT perl_record_set();
 
201
ERROR:  function returning record called in context that cannot accept type record
 
202
SELECT * FROM perl_record_set();
 
203
ERROR:  a column definition list is required for functions returning "record"
 
204
SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
 
205
ERROR:  elements of Perl result array must be reference to hash
 
206
CREATE OR REPLACE FUNCTION perl_record_set() RETURNS SETOF record AS $$
 
207
    return [
 
208
        { f1 => 1, f2 => 'Hello', f3 =>  'World' },
 
209
        { f1 => 2, f2 => 'Hello', f3 =>  'PostgreSQL' },
 
210
        { f1 => 3, f2 => 'Hello', f3 =>  'PL/Perl' }
 
211
    ];
 
212
$$  LANGUAGE plperl;
 
213
SELECT perl_record_set();
 
214
ERROR:  function returning record called in context that cannot accept type record
 
215
SELECT * FROM perl_record_set();
 
216
ERROR:  a column definition list is required for functions returning "record"
 
217
SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
 
218
 f1 |  f2   |     f3     
 
219
----+-------+------------
 
220
  1 | Hello | World
 
221
  2 | Hello | PostgreSQL
 
222
  3 | Hello | PL/Perl
 
223
(3 rows)
 
224
 
 
225
CREATE TYPE footype AS (x INTEGER, y INTEGER);
 
226
CREATE OR REPLACE FUNCTION foo_good() RETURNS SETOF footype AS $$
 
227
return [
 
228
    {x => 1, y => 2},
 
229
    {x => 3, y => 4}
 
230
];
 
231
$$ LANGUAGE plperl;
 
232
SELECT * FROM foo_good();
 
233
 x | y 
 
234
---+---
 
235
 1 | 2
 
236
 3 | 4
 
237
(2 rows)
 
238
 
 
239
CREATE OR REPLACE FUNCTION foo_bad() RETURNS footype AS $$
 
240
    return {y => 3, z => 4};
 
241
$$ LANGUAGE plperl;
 
242
SELECT * FROM foo_bad();
 
243
ERROR:  Perl hash contains nonexistent column "z"
 
244
CREATE OR REPLACE FUNCTION foo_bad() RETURNS footype AS $$
 
245
return 42;
 
246
$$ LANGUAGE plperl;
 
247
SELECT * FROM foo_bad();
 
248
ERROR:  composite-returning Perl function must return reference to hash
 
249
CREATE OR REPLACE FUNCTION foo_bad() RETURNS footype AS $$
 
250
return [
 
251
    [1, 2],
 
252
    [3, 4]
 
253
];
 
254
$$ LANGUAGE plperl;
 
255
SELECT * FROM foo_bad();
 
256
ERROR:  composite-returning Perl function must return reference to hash
 
257
CREATE OR REPLACE FUNCTION foo_set_bad() RETURNS SETOF footype AS $$
 
258
    return 42;
 
259
$$ LANGUAGE plperl;
 
260
SELECT * FROM foo_set_bad();
 
261
ERROR:  set-returning Perl function must return reference to array
 
262
CREATE OR REPLACE FUNCTION foo_set_bad() RETURNS SETOF footype AS $$
 
263
    return {y => 3, z => 4};
 
264
$$ LANGUAGE plperl;
 
265
SELECT * FROM foo_set_bad();
 
266
ERROR:  set-returning Perl function must return reference to array
 
267
CREATE OR REPLACE FUNCTION foo_set_bad() RETURNS SETOF footype AS $$
 
268
return [
 
269
    [1, 2],
 
270
    [3, 4]
 
271
];
 
272
$$ LANGUAGE plperl;
 
273
SELECT * FROM foo_set_bad();
 
274
ERROR:  elements of Perl result array must be reference to hash
 
275
CREATE OR REPLACE FUNCTION foo_set_bad() RETURNS SETOF footype AS $$
 
276
return [
 
277
    {y => 3, z => 4}
 
278
];
 
279
$$ LANGUAGE plperl;
 
280
SELECT * FROM foo_set_bad();
 
281
ERROR:  Perl hash contains nonexistent column "z"
 
282
CREATE OR REPLACE FUNCTION perl_get_field(footype, text) RETURNS integer AS $$
 
283
    return $_[0]->{$_[1]};
 
284
$$ LANGUAGE plperl;
 
285
SELECT perl_get_field((11,12), 'x');
 
286
 perl_get_field 
 
287
----------------
 
288
             11
 
289
(1 row)
 
290
 
 
291
SELECT perl_get_field((11,12), 'y');
 
292
 perl_get_field 
 
293
----------------
 
294
             12
 
295
(1 row)
 
296
 
 
297
SELECT perl_get_field((11,12), 'z');
 
298
 perl_get_field 
 
299
----------------
 
300
               
 
301
(1 row)
 
302