proposal: generic function, constructor function

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема proposal: generic function, constructor function
Дата
Msg-id 162867790801181033r2f4d8086i740db9bf306b6fa3@mail.gmail.com
обсуждение исходный текст
Ответы Re: proposal: generic function, constructor function  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Hello

I propose two kinds of functions:

a) generic functions - this function allows any params without any
implicit casting (it can implemented only in C language). This
function have to have specified return type. It usable for constructor
function and for some other. It allows unspecified number of params
without parser changes. There are not limits for params (only max
number) and there are not any implicit casting. Any parameter can take
additional tag with AS keyword.

Limits: only one function with specified name can exists in schema.

Sample:

CREATE FUNCTION format(any)
RETURNS text LANGUAGE C ....;

SELECT format(1, 'aaa' AS b, ARRAY[1,2,3]) -> '(1, b:"aaa",[1,2,3])'

generic function can be well used for constructor function

b) constructor function - this function returns typed composite or
array value. It's in conformance with ANSI SQL. Constructor function
is any  generic function where name is same like any composite type or
domain. Behave of constructor is same for all types.

Sample:
CREATE TYPE ftype AS (a integer, b integer);

SELECT ftype(), ftype(10), ftype(10,20); -> (NULL, NULL), (10,NULL), (10,20) ~ (10,20)::ftype

CREATE DOMAIN fdom AS int[];

SELECT fdom(), fdom(10,20,30); -> '{}','{10,20,30}'; ~ it's eq ARRAY[10,20,30]::int[];

Why constructors?

Composite values are referenced in SQL/PSM. When I wont to fill
composite variables directly, I have to call constructor before:

DECLARE v mytype;
SET v = mytype();
SET v.f = 10; ~ or shortly SET v = mytype(10);

Any comments are welcome

Regards
Pavel Stehule


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

Предыдущее
От: Maciej Grygorcewicz
Дата:
Сообщение: Problem with correct compiling and linking server side C function on Windows ,c++ Builder
Следующее
От: "Kevin Grittner"
Дата:
Сообщение: Re: testing result overview (was: 8.3 beta testing suggestions welcome)