Re: syntax question

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: syntax question
Дата
Msg-id c58b04ac-e713-f089-8400-763a742bf86d@aklaver.com
обсуждение исходный текст
Ответ на Re: syntax question  (Bruce Momjian <bruce@momjian.us>)
Ответы Re: syntax question  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: syntax question  (Marc Millas <marc.millas@mokadb.com>)
Список pgsql-general
On 6/3/21 12:01 PM, Bruce Momjian wrote:
> On Thu, Jun  3, 2021 at 08:58:03PM +0200, Marc Millas wrote:
>> Hi,
>>
>> within a function, I want to create another function.
>> no pb.
>> but if I write:
>> declare bidule text;
>> begin
>> bidule:='myfunc';
>> create function bidule() ...
>>
>>
>> it does create a function named bidule and not myfunc.
>> so I am obviously missing something too obvious.
> 
> You can't create functions inside of functions;  same for procedures.
> 

Sure you can:

CREATE OR REPLACE FUNCTION public.test_fnc()
  RETURNS void
  LANGUAGE plpgsql
AS $function$
DECLARE
      bidule text;
BEGIN
bidule:='myfunc';
EXECUTE  'create function ' ||  bidule || '() RETURNS void language 
plpgsql AS $fnc$ BEGIN END; $fnc$ ';
END;


$function$

select test_fnc();
  test_fnc
----------

  \df myfunc
                         List of functions
  Schema |  Name  | Result data type | Argument data types | Type
--------+--------+------------------+---------------------+------
  public | myfunc | void             |                     | func


Whether you should is another question.


-- 
Adrian Klaver
adrian.klaver@aklaver.com



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

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: syntax question
Следующее
От: Tom Lane
Дата:
Сообщение: Re: syntax question