Thread: How can udf c function return table, not the rows?
Hi hackers,
I am trying to design a new "pg_get_functiondef" function extension, like this:
CREATE FUNCTION pg_get_functiondef(OID, VARIADIC OID[]) RETURNS TABLE (OID oid, pg_get_functiondef text)
AS 'pg_get_functiondef', 'pg_get_functiondef_mul'
LANGUAGE C;
AS 'pg_get_functiondef', 'pg_get_functiondef_mul'
LANGUAGE C;
And I have read the <C-Language Functions>, learn the way to build the tuple (use
BlessTupleDesc or
BuildTupleFromCStrings
) to return the Composite Types, but when I finish my work, its performance does not meet my expectations, like this: pg_get_functiondef
----------------------------------------------------------------------
(1400,"CREATE OR REPLACE FUNCTION pg_catalog.name(character varying)+
RETURNS name +
LANGUAGE internal +
IMMUTABLE PARALLEL SAFE STRICT LEAKPROOF +
AS $function$text_name$function$ +
")
(1400,"CREATE OR REPLACE FUNCTION pg_catalog.name(character varying)+
RETURNS name +
LANGUAGE internal +
IMMUTABLE PARALLEL SAFE STRICT LEAKPROOF +
AS $function$text_name$function$ +
")
----------------------------------------------------------------------
(1400,"CREATE OR REPLACE FUNCTION pg_catalog.name(character varying)+
RETURNS name +
LANGUAGE internal +
IMMUTABLE PARALLEL SAFE STRICT LEAKPROOF +
AS $function$text_name$function$ +
")
(1400,"CREATE OR REPLACE FUNCTION pg_catalog.name(character varying)+
RETURNS name +
LANGUAGE internal +
IMMUTABLE PARALLEL SAFE STRICT LEAKPROOF +
AS $function$text_name$function$ +
")
In my expectations, it should be:
RETURNS name +
LANGUAGE internal +
IMMUTABLE PARALLEL SAFE STRICT LEAKPROOF +
AS $function$text_name$function' AS pg_get_functiondef;
oid | pg_get_functiondef
------+------------------------------------------------------------------------
1400 | CREATE OR REPLACE FUNCTION pg_catalog.name(character varying)+ +
| RETURNS name ++
| LANGUAGE internal ++
| IMMUTABLE PARALLEL SAFE STRICT LEAKPROOF ++
| AS $function$text_name$function
(1 row)
Because I write:
TupleDescInitEntry(info->result_desc, 1, "OID", OIDOID, -1, 0);
TupleDescInitEntry(info->result_desc, 2, "pg_get_functiondef", CSTRINGOID, -1, 0);
TupleDescInitEntry(info->result_desc, 2, "pg_get_functiondef", CSTRINGOID, -1, 0);
Can someone give my some advice?
Thanks in advance!
Yours,
Wen Yi
On Thursday, July 18, 2024, Wen Yi <wen-yi@qq.com> wrote:
pg_get_functiondef
------------------------------------------------------------ ---------- In my expectations, it should be:oid | pg_get_functiondef
------+----------------------------------------------------- ------------------- Can someone give my some advice?
Write:
Select * from function_call()
Instead of
Select function_call()
Guessing a bit since you never did show the first query.
David J.