From: | "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | "Pgsql Hackers" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | proposal: generic function, constructor function |
Date: | 2008-01-18 18:33:57 |
Message-ID: | 162867790801181033r2f4d8086i740db9bf306b6fa3@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Kevin Grittner | 2008-01-18 19:08:46 | Re: testing result overview (was: 8.3 beta testing suggestions welcome) |
Previous Message | Maciej Grygorcewicz | 2008-01-18 18:30:41 | Problem with correct compiling and linking server side C function on Windows ,c++ Builder |