File: plproxy_dynamic_record.out

package info (click to toggle)
postgresql-plproxy 2.11.0-12
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 564 kB
  • sloc: ansic: 3,476; sql: 1,136; lex: 340; yacc: 171; makefile: 93; sh: 18; awk: 14
file content (60 lines) | stat: -rw-r--r-- 1,990 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-- dynamic query support testing
create or replace function dynamic_query(q text)
returns setof record as $x$
    cluster 'map0';
    run on all;
$x$ language plproxy;
\c test_part0
create or replace function dynamic_query(q text)
returns setof record as $x$
declare
    ret record;
begin
    for ret in execute q loop
        return next ret;
    end loop;
    return;
end;
$x$ language plpgsql;
create table dynamic_query_test (
    id integer,
    username text,
		other	text
);
insert into dynamic_query_test values ( 1, 'user1', 'blah');
insert into dynamic_query_test values ( 2, 'user2', 'foo');
\c regression
select * from dynamic_query('select * from dynamic_query_test') as (id integer, username text, other text);
 id | username | other 
----+----------+-------
  1 | user1    | blah
  2 | user2    | foo
(2 rows)

select * from dynamic_query('select id, username from dynamic_query_test') as foo(id integer, username text);
 id | username 
----+----------
  1 | user1
  2 | user2
(2 rows)

-- invalid usage
select * from dynamic_query('select count(1) from pg_class');
ERROR:  a column definition list is required for functions returning "record"
LINE 1: select * from dynamic_query('select count(1) from pg_class')...
                      ^
select dynamic_query('select count(1) from pg_class');
ERROR:  Function used in wrong context
-- test errors
create or replace function dynamic_query_select()
returns setof record as $x$
    cluster 'map0';
    run on all;
    select id, username from dynamic_query_test;
$x$ language plproxy;
ERROR:  PL/Proxy function public.dynamic_query_select(0): SELECT statement not allowed for dynamic RECORD functions
select * from dynamic_query_select() as (id integer, username text);
ERROR:  function dynamic_query_select() does not exist
LINE 1: select * from dynamic_query_select() as (id integer, usernam...
                      ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.