diff options
| author | Tom Lane | 2009-12-14 02:15:54 +0000 |
|---|---|---|
| committer | Tom Lane | 2009-12-14 02:15:54 +0000 |
| commit | a620d5005df6e4b6fc09ba914f19402dc07289dd (patch) | |
| tree | c7213f3647c9b6600ed3d95e352790d8ae0f7744 /src/test | |
| parent | 84f910a7076e09e551bf69e0972473ec15d33c79 (diff) | |
Fix a bug introduced when set-returning SQL functions were made inline-able:
we have to cope with the possibility that the declared result rowtype contains
dropped columns. This fails in 8.4, as per bug #5240.
While at it, be more paranoid about inserting binary coercions when inlining.
The pre-8.4 code did not really need to worry about that because it could not
inline at all in any case where an added coercion could change the behavior
of the function's statement. However, when inlining a SRF we allow sorting,
grouping, and set-ops such as UNION. In these cases, modifying one of the
targetlist entries that the sort/group/setop depends on could conceivably
change the behavior of the function's statement --- so don't inline when
such a case applies.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/rangefuncs.out | 61 | ||||
| -rw-r--r-- | src/test/regress/sql/rangefuncs.sql | 38 |
2 files changed, 99 insertions, 0 deletions
diff --git a/src/test/regress/expected/rangefuncs.out b/src/test/regress/expected/rangefuncs.out index 843bc53e4e7..a32cbf5f795 100644 --- a/src/test/regress/expected/rangefuncs.out +++ b/src/test/regress/expected/rangefuncs.out @@ -836,3 +836,64 @@ ERROR: a column definition list is required for functions returning "record" LINE 1: select * from testfoo(); ^ drop function testfoo(); +-- +-- Check some cases involving dropped columns in a rowtype result +-- +create temp table users (userid text, email text, todrop bool, enabled bool); +insert into users values ('id','email',true,true); +insert into users values ('id2','email2',true,true); +alter table users drop column todrop; +create or replace function get_first_user() returns users as +$$ SELECT * FROM users ORDER BY userid LIMIT 1; $$ +language sql stable; +SELECT get_first_user(); + get_first_user +---------------- + (id,email,t) +(1 row) + +SELECT * FROM get_first_user(); + userid | email | enabled +--------+-------+--------- + id | email | t +(1 row) + +create or replace function get_users() returns setof users as +$$ SELECT * FROM users ORDER BY userid; $$ +language sql stable; +SELECT get_users(); + get_users +---------------- + (id,email,t) + (id2,email2,t) +(2 rows) + +SELECT * FROM get_users(); + userid | email | enabled +--------+--------+--------- + id | email | t + id2 | email2 | t +(2 rows) + +drop function get_first_user(); +drop function get_users(); +drop table users; +-- this won't get inlined because of type coercion, but it shouldn't fail +create or replace function foobar() returns setof text as +$$ select 'foo'::varchar union all select 'bar'::varchar ; $$ +language sql stable; +select foobar(); + foobar +-------- + foo + bar +(2 rows) + +select * from foobar(); + foobar +-------- + foo + bar +(2 rows) + +drop function foobar(); diff --git a/src/test/regress/sql/rangefuncs.sql b/src/test/regress/sql/rangefuncs.sql index 172bbc73a9e..db74770228d 100644 --- a/src/test/regress/sql/rangefuncs.sql +++ b/src/test/regress/sql/rangefuncs.sql @@ -391,3 +391,41 @@ select * from testfoo() as t(f1 int8,f2 int8); select * from testfoo(); -- fail drop function testfoo(); + +-- +-- Check some cases involving dropped columns in a rowtype result +-- + +create temp table users (userid text, email text, todrop bool, enabled bool); +insert into users values ('id','email',true,true); +insert into users values ('id2','email2',true,true); +alter table users drop column todrop; + +create or replace function get_first_user() returns users as +$$ SELECT * FROM users ORDER BY userid LIMIT 1; $$ +language sql stable; + +SELECT get_first_user(); +SELECT * FROM get_first_user(); + +create or replace function get_users() returns setof users as +$$ SELECT * FROM users ORDER BY userid; $$ +language sql stable; + +SELECT get_users(); +SELECT * FROM get_users(); + +drop function get_first_user(); +drop function get_users(); +drop table users; + +-- this won't get inlined because of type coercion, but it shouldn't fail + +create or replace function foobar() returns setof text as +$$ select 'foo'::varchar union all select 'bar'::varchar ; $$ +language sql stable; + +select foobar(); +select * from foobar(); + +drop function foobar(); |
