mirror of
https://github.com/postgres/postgres.git
synced 2025-07-09 22:41:56 +03:00
This patch adds support for %TYPE in CREATE FUNCTION argument and return
types. This version has an elog() to remind the user the type resolution is not dynamic. Ian Lance Taylor
This commit is contained in:
@ -13,6 +13,12 @@ CREATE FUNCTION hobby_construct(text, text)
|
||||
LANGUAGE 'sql';
|
||||
|
||||
|
||||
CREATE FUNCTION hobbies_by_name(hobbies_r.name%TYPE)
|
||||
RETURNS hobbies_r.person%TYPE
|
||||
AS 'select person from hobbies_r where name = $1'
|
||||
LANGUAGE 'sql';
|
||||
|
||||
|
||||
CREATE FUNCTION equipment(hobbies_r)
|
||||
RETURNS setof equipment_r
|
||||
AS 'select * from equipment_r where hobby = $1.name'
|
||||
|
@ -214,6 +214,7 @@ SELECT user_relns() AS user_relns
|
||||
|
||||
--SELECT name(equipment(hobby_construct(text 'skywalking', text 'mer'))) AS equip_name;
|
||||
|
||||
SELECT hobbies_by_name('basketball');
|
||||
|
||||
--
|
||||
-- check that old-style C functions work properly with TOASTed values
|
||||
|
@ -9,6 +9,12 @@ CREATE FUNCTION hobby_construct(text, text)
|
||||
RETURNS hobbies_r
|
||||
AS 'select $1 as name, $2 as hobby'
|
||||
LANGUAGE 'sql';
|
||||
CREATE FUNCTION hobbies_by_name(hobbies_r.name%TYPE)
|
||||
RETURNS hobbies_r.person%TYPE
|
||||
AS 'select person from hobbies_r where name = $1'
|
||||
LANGUAGE 'sql';
|
||||
NOTICE: hobbies_r.name%TYPE converted to text
|
||||
NOTICE: hobbies_r.person%TYPE converted to text
|
||||
CREATE FUNCTION equipment(hobbies_r)
|
||||
RETURNS setof equipment_r
|
||||
AS 'select * from equipment_r where hobby = $1.name'
|
||||
|
@ -656,6 +656,12 @@ SELECT user_relns() AS user_relns
|
||||
(90 rows)
|
||||
|
||||
--SELECT name(equipment(hobby_construct(text 'skywalking', text 'mer'))) AS equip_name;
|
||||
SELECT hobbies_by_name('basketball');
|
||||
hobbies_by_name
|
||||
-----------------
|
||||
joe
|
||||
(1 row)
|
||||
|
||||
--
|
||||
-- check that old-style C functions work properly with TOASTed values
|
||||
--
|
||||
|
Reference in New Issue
Block a user