[Feature request] variable declaration of anonymous composite data type in PL/pgSQL

Lists: pgsql-hackers
From: Maciej Mrozowski <reavertm(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: [Feature request] variable declaration of anonymous composite data type in PL/pgSQL
Date: 2010-03-01 23:08:31
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Hello,

Not sure whether it's appropriate list for feature requests though..
Would it be suitable to implement such variable declarations in PL/pgSQL so
that following (or similar) constructs would be possible?

DECLARE
tmpStruct (name varchar, foo integer, bar boolean)[] := array[
('somename', 1, true),
('someothername', 2, false),
('yetothername', 3, true)
];
BEGIN
...

Or maybe it is possible already? (I know there are temporary tables but it's
not quite the same). The goal to have temporary local random access data
structures (like lookup tables), similar to those in C.

--
regards
MM


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Maciej Mrozowski <reavertm(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [Feature request] variable declaration of anonymous composite data type in PL/pgSQL
Date: 2010-03-02 00:08:05
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

Maciej Mrozowski wrote:
> Hello,
>
> Not sure whether it's appropriate list for feature requests though..
> Would it be suitable to implement such variable declarations in PL/pgSQL so
> that following (or similar) constructs would be possible?
>
> DECLARE
> tmpStruct (name varchar, foo integer, bar boolean)[] := array[
> ('somename', 1, true),
> ('someothername', 2, false),
> ('yetothername', 3, true)
> ];
> BEGIN
> ...
>
> Or maybe it is possible already? (I know there are temporary tables but it's
> not quite the same). The goal to have temporary local random access data
> structures (like lookup tables), similar to those in C.
>
>

There have certainly been time I could have used this. You can get close
using VALUES:

create or replace function foo()
returns void
language plpgsql as
$$

declare
rec record;
begin
for rec in
select *
from (values
(1::int,'a'::text,'2009-08-06'::date),
(5,'wxy','1998-12-23'))
as x (a , b , c )
loop
raise notice 'a: %, b: %, c: %',
rec.a + 1,
length(rec.b),
rec.c + interval '1 day';
end loop;
end;

$$;

cheers

andrew