Обсуждение: proposal: plpgsql, solution for derivated types of parameters

Поиск
Список
Период
Сортировка

proposal: plpgsql, solution for derivated types of parameters

От
Pavel Stehule
Дата:
Hello,

the current plpgsql syntax doesn't offer a functionality to define
some variable with type as element of some other array variable or
reverse order. The primary goal of this proposal is enahancing plpgsql
for better working with polymorphic types.

I propose a following syntax:

-- variable as element of some array
DECLARE elementvar IS ELEMENT OF arrayvar;
DECLARE elementvar IS ELEMENT OF arrayvar%type

-- variable as array of some variable
DECLARE arrayvar IS ARRAY OF varname;
DECLARE arrayvar IS ARRAY OF varname%type

This proposal doesn't introduce any new reserved keywords.

Comments?

Regards

Pavel Stehule


Re: proposal: plpgsql, solution for derivated types of parameters

От
Itagaki Takahiro
Дата:
On Fri, Oct 8, 2010 at 3:08 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
> I propose a following syntax:
>
> -- variable as element of some array
> DECLARE elementvar IS ELEMENT OF arrayvar;
> DECLARE elementvar IS ELEMENT OF arrayvar%type
>
> -- variable as array of some variable
> DECLARE arrayvar IS ARRAY OF varname;
> DECLARE arrayvar IS ARRAY OF varname%type
>
> This proposal doesn't introduce any new reserved keywords.

FYI, Oracle PL/SQL supports type declaration and array
variables are declare as the type.
 DECLARE   TYPE array_type_name IS {VARRAY | VARYING ARRAY} (size_limit)     OF element_type [NOT NULL];   a1
array_type_name;

"IS ARRAY OF" syntax is similar enough to PL/SQL, but is not compatible.

I'm not sure whether PL/SQL has "IS ELEMENT OF" variants.

-- 
Itagaki Takahiro


Re: proposal: plpgsql, solution for derivated types of parameters

От
Pavel Stehule
Дата:
2010/10/8 Itagaki Takahiro <itagaki.takahiro@gmail.com>:
> On Fri, Oct 8, 2010 at 3:08 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
>> I propose a following syntax:
>>
>> -- variable as element of some array
>> DECLARE elementvar IS ELEMENT OF arrayvar;
>> DECLARE elementvar IS ELEMENT OF arrayvar%type
>>
>> -- variable as array of some variable
>> DECLARE arrayvar IS ARRAY OF varname;
>> DECLARE arrayvar IS ARRAY OF varname%type
>>
>> This proposal doesn't introduce any new reserved keywords.
>
> FYI, Oracle PL/SQL supports type declaration and array
> variables are declare as the type.
>
>  DECLARE
>    TYPE array_type_name IS {VARRAY | VARYING ARRAY} (size_limit)
>      OF element_type [NOT NULL];
>    a1 array_type_name;
>
> "IS ARRAY OF" syntax is similar enough to PL/SQL, but is not compatible.

it is compatible, but used in different place (clause).

>
> I'm not sure whether PL/SQL has "IS ELEMENT OF" variants.
>

yes, it is inspiration. I think so we can use this pattern because
plpgsql cannot to declare a local type. IS ELEMENT OF isn't supported
by Oracle. But Oracle must not solve this problem, because it doesn't
support a polymorphic types.

Pavel

> --
> Itagaki Takahiro
>


Re: proposal: plpgsql, solution for derivated types of parameters

От
Tom Lane
Дата:
Pavel Stehule <pavel.stehule@gmail.com> writes:
> the current plpgsql syntax doesn't offer a functionality to define
> some variable with type as element of some other array variable or
> reverse order. The primary goal of this proposal is enahancing plpgsql
> for better working with polymorphic types.

I haven't seen any actual field complaints that would be solved by this.
How often is it really going to be useful?

> DECLARE elementvar IS ELEMENT OF arrayvar;
> DECLARE arrayvar IS ARRAY OF varname;

Both of these notations seem pretty inconsistent with the rest of
plpgsql, as well as being dead ends when you think about extensions to
more complex situations like arrays of records or records of arrays.
I'd expect to do the former with something like "arrayvar[0]%type" and
the latter with "var%type[]".  Possibly some parentheses would be needed
to make this non-ambiguous.
        regards, tom lane


Re: proposal: plpgsql, solution for derivated types of parameters

От
Pavel Stehule
Дата:
2010/10/8 Tom Lane <tgl@sss.pgh.pa.us>:
> Pavel Stehule <pavel.stehule@gmail.com> writes:
>> the current plpgsql syntax doesn't offer a functionality to define
>> some variable with type as element of some other array variable or
>> reverse order. The primary goal of this proposal is enahancing plpgsql
>> for better working with polymorphic types.
>
> I haven't seen any actual field complaints that would be solved by this.
> How often is it really going to be useful?
>
>> DECLARE elementvar IS ELEMENT OF arrayvar;
>> DECLARE arrayvar IS ARRAY OF varname;
>
> Both of these notations seem pretty inconsistent with the rest of
> plpgsql, as well as being dead ends when you think about extensions to
> more complex situations like arrays of records or records of arrays.
> I'd expect to do the former with something like "arrayvar[0]%type" and

uff  "arrayvar[0]%type" should be in plpgsql spirit? There is nothing
similar in Ada, PL/SQL or languages similar to modula. I don't see why
my proposal cannot work with more complex types. This is maybe C
construct - it must not be used for plpgsql - subscripts can start
with other number than zero.

DECLARE arrayvar IS ARRAY OF sometype

or

DECLARE arrayvar IS ARRAY OF somevar%type;

possible

DECLARE arrayvar IS ARRAY OF somerec.field%type;

This syntax is similar to Ada language.



> the latter with "var%type[]".  Possibly some parentheses would be needed
> to make this non-ambiguous.
>
>                        regards, tom lane
>