Re: plpgsql - DECLARE - cannot to use %TYPE or %ROWTYPE for composite types - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: plpgsql - DECLARE - cannot to use %TYPE or %ROWTYPE for composite types
Date
Msg-id CAFj8pRCacWg=hEPethghc_WgnQ0RUeVwvQCDTa1FhtE2Xo-EGw@mail.gmail.com
Whole thread Raw
In response to Re: plpgsql - DECLARE - cannot to use %TYPE or %ROWTYPE for composite types  (Peter Eisentraut <peter_e@gmx.net>)
Responses Re: plpgsql - DECLARE - cannot to use %TYPE or %ROWTYPE for composite types
List pgsql-hackers
Hi

2016-02-24 22:18 GMT+01:00 Peter Eisentraut <peter_e@gmx.net>:
On 1/18/16 4:21 PM, Robert Haas wrote:
> One idea that occurs to me is: If you can DECLARE BAR FOO%TYPE, but
> then you want to make BAR an array of that type rather than a scalar,
> why not write that as DECLARE BAR FOO%TYPE[]?  That seems quite
> natural to me.

Right, and it's arguably dubious that that doesn't already work.
Unfortunately, these % things are just random plpgsql parser hacks, not
real types.  Maybe this should be done in the main PostgreSQL parser
with parameter hooks, if we wanted this feature to be available outside
plpgsql as well.

I am not fan to propagate this feature outside PLpgSQL - it is possible new dependency between database object, and the cost is higher than benefits.
 

> I think the part of this patch that makes %TYPE work for more kinds of
> types is probably a good idea, although I haven't carefully studied
> exactly what it does.

I agree that this should be more general.  For instance, this patch
would allow you to get the element type of an array-typed variable, but
there is no way to get the element type of just another type.  If we
could do something like

DECLARE
  var ELEMENT OF point;

isn't it bug? What is sense of this construct? Our other manipulation with a arrays we raise a error, when we try to to take a element from non array value.

Today I did work on this patch and I am able to implement the syntax proposed by you. It is proprietary, but similar to ADA anonymous types.

DECLARE x array() of type

Regards

Pavel
 

(not necessary that syntax)

then

DECLARE
  var ELEMENT OF othervar%TYPE;

should just fall into place.


pgsql-hackers by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: pg_dump dump catalog ACLs
Next
From: Stephen Frost
Date:
Subject: Re: pg_dump dump catalog ACLs