From: | Wen Yi <wen-yi(at)qq(dot)com> |
---|---|
To: | pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | How can udf c function return table, not the rows? |
Date: | 2024-07-19 06:57:51 |
Message-ID: | tencent_096A82690AE4661C9F1BAC7496CB7E9DC606@qq.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
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;
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$ +
")
In my expectations, it should be:
postgres=# SELECT 1400 AS oid, 'CREATE OR REPLACE FUNCTION pg_catalog.name(character varying)+
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);
Can someone give my some advice?
Thanks in advance!
Yours,
Wen Yi
From | Date | Subject | |
---|---|---|---|
Next Message | Hao Zhang | 2024-07-19 07:11:25 | Can we use parallel workers to create index without active/transaction snapshot? |
Previous Message | jian he | 2024-07-19 06:55:00 | Re: documentation structure |