diff options
author | Bruce Momjian | 2006-05-30 12:03:13 +0000 |
---|---|---|
committer | Bruce Momjian | 2006-05-30 12:03:13 +0000 |
commit | 38c7700f56cc44377a1b46b4ff41ee57ae21e428 (patch) | |
tree | de22aa6f47791a2c6e4aaae31f373d2baec4f028 /src/test | |
parent | 88ba64d3963e2dff92426103ab7891a32032900e (diff) |
Add dynamic record inspection to PL/PgSQL, useful for generic triggers:
tval2 := r.(cname);
or
columns := r.(*);
Titus von Boxberg
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/regress/expected/plpgsql.out | 38 | ||||
-rw-r--r-- | src/test/regress/sql/plpgsql.sql | 32 |
2 files changed, 70 insertions, 0 deletions
diff --git a/src/test/regress/expected/plpgsql.out b/src/test/regress/expected/plpgsql.out index 6e6597dadb2..e20d76c0aeb 100644 --- a/src/test/regress/expected/plpgsql.out +++ b/src/test/regress/expected/plpgsql.out @@ -2725,6 +2725,44 @@ end; $$ language plpgsql; ERROR: end label "outer_label" specified for unlabelled block CONTEXT: compile of PL/pgSQL function "end_label4" near line 5 +-- check introspective records +create table ritest (i INT4, t TEXT); +insert into ritest (i, t) VALUES (1, 'sometext'); +create function test_record() returns void as $$ +declare + cname text; + tval text; + ival int4; + tval2 text; + ival2 int4; + columns text[]; + r RECORD; +begin + SELECT INTO r * FROM ritest WHERE i = 1; + ival := r.i; + tval := r.t; + RAISE NOTICE 'ival=%, tval=%', ival, tval; + cname := 'i'; + ival2 := r.(cname); + cname :='t'; + tval2 := r.(cname); + RAISE NOTICE 'ival2=%, tval2=%', ival2, tval2; + columns := r.(*); + RAISE NOTICE 'fieldnames=%', columns; + RETURN; +end; +$$ language plpgsql; +select test_record(); +NOTICE: ival=1, tval=sometext +NOTICE: ival2=1, tval2=sometext +NOTICE: fieldnames={i,t} + test_record +------------- + + (1 row) + +drop table ritest; +drop function test_record(); -- using list of scalars in fori and fore stmts create function for_vect() returns void as $proc$ <<lbl>>declare a integer; b varchar; c varchar; r record; diff --git a/src/test/regress/sql/plpgsql.sql b/src/test/regress/sql/plpgsql.sql index 19e145be65f..05460629860 100644 --- a/src/test/regress/sql/plpgsql.sql +++ b/src/test/regress/sql/plpgsql.sql @@ -2281,6 +2281,38 @@ begin end; $$ language plpgsql; +-- check introspective records +create table ritest (i INT4, t TEXT); +insert into ritest (i, t) VALUES (1, 'sometext'); +create function test_record() returns void as $$ +declare + cname text; + tval text; + ival int4; + tval2 text; + ival2 int4; + columns text[]; + r RECORD; +begin + SELECT INTO r * FROM ritest WHERE i = 1; + ival := r.i; + tval := r.t; + RAISE NOTICE 'ival=%, tval=%', ival, tval; + cname := 'i'; + ival2 := r.(cname); + cname :='t'; + tval2 := r.(cname); + RAISE NOTICE 'ival2=%, tval2=%', ival2, tval2; + columns := r.(*); + RAISE NOTICE 'fieldnames=%', columns; + RETURN; +end; +$$ language plpgsql; +select test_record(); +drop table ritest; +drop function test_record(); + + -- using list of scalars in fori and fore stmts create function for_vect() returns void as $proc$ <<lbl>>declare a integer; b varchar; c varchar; r record; |