How can udf c function return table, not the rows?

Поиск
Список
Период
Сортировка
От Wen Yi
Тема How can udf c function return table, not the rows?
Дата
Msg-id tencent_096A82690AE4661C9F1BAC7496CB7E9DC606@qq.com
обсуждение исходный текст
Ответы How can udf c function return table, not the rows?
Список 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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: jian he
Дата:
Сообщение: Re: documentation structure
Следующее
От: Hao Zhang
Дата:
Сообщение: Can we use parallel workers to create index without active/transaction snapshot?