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

From Artur Zakirov
Subject Re: plpgsql - DECLARE - cannot to use %TYPE or %ROWTYPE for composite types
Date
Msg-id 56C6E357.4080604@postgrespro.ru
Whole thread Raw
In response to Re: plpgsql - DECLARE - cannot to use %TYPE or %ROWTYPE for composite types  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: plpgsql - DECLARE - cannot to use %TYPE or %ROWTYPE for composite types
List pgsql-hackers
It seems all fixes are done. I tested the patch and regression tests passed.

On 27.01.2016 20:58, Pavel Stehule wrote:
>
>
>      > --- 1681,1687 ----
>      >    * ----------
>      >    */
>      >   PLpgSQL_type *
>      > ! plpgsql_parse_wordtype(char *ident, int reftype_mode)
>      >   {
>      >       PLpgSQL_type *dtype;
>      >       PLpgSQL_nsitem *nse;
>
>     Use the typedef'ed enum, as above.
>
>      > --- 1699,1721 ----
>      >               switch (nse->itemtype)
>      >               {
>      >                       case PLPGSQL_NSTYPE_VAR:
>      > !                     {
>      > !                             dtype = ((PLpgSQL_var *)
>     (plpgsql_Datums[nse->itemno]))->datatype;
>      > !                             return derive_type(dtype,
>     reftype_mode);
>      > !                     }
>      >
>      > !                     case PLPGSQL_NSTYPE_ROW:
>      > !                     {
>      > !                             dtype = ((PLpgSQL_row *)
>     (plpgsql_Datums[nse->itemno]))->datatype;
>      > !                             return derive_type(dtype,
>     reftype_mode);
>      > !                     }
>      >
>      > +                     /*
>      > +                      * XXX perhaps allow REC here? Probably it
>     has not any sense, because
>      > +                      * in this moment, because PLpgSQL doesn't
>     support rec parameters, so
>      > +                      * there should not be any rec polymorphic
>     parameter, and any work can
>      > +                      * be done inside function.
>      > +                      */
>
>     I think you should remove from the "?" onwards in that comment, i.e.
>     just keep what was already in the original comment (minus the ROW)
>
>
> I tried to fix it, not sure if understood well.

I think here Alvaro means that you should keep original comment without 
the ROW. Like this:

/* XXX perhaps allow REC here? */

>
>      > *************** extern bool plpgsql_parse_dblword(char *
>      > *** 961,968 ****
>      >                                         PLwdatum *wdatum, PLcword
>     *cword);
>      >   extern bool plpgsql_parse_tripword(char *word1, char *word2,
>     char *word3,
>      >                                          PLwdatum *wdatum,
>     PLcword *cword);
>      > ! extern PLpgSQL_type *plpgsql_parse_wordtype(char *ident);
>      > ! extern PLpgSQL_type *plpgsql_parse_cwordtype(List *idents);
>      >   extern PLpgSQL_type *plpgsql_parse_wordrowtype(char *ident);
>      >   extern PLpgSQL_type *plpgsql_parse_cwordrowtype(List *idents);
>      >   extern PLpgSQL_type *plpgsql_build_datatype(Oid typeOid, int32
>     typmod,
>      > --- 973,980 ----
>      >                                         PLwdatum *wdatum, PLcword
>     *cword);
>      >   extern bool plpgsql_parse_tripword(char *word1, char *word2,
>     char *word3,
>      >                                          PLwdatum *wdatum,
>     PLcword *cword);
>      > ! extern PLpgSQL_type *plpgsql_parse_wordtype(char *ident, int
>     reftype_mode);
>      > ! extern PLpgSQL_type *plpgsql_parse_cwordtype(List *idents, int
>     reftype_mode);
>      >   extern PLpgSQL_type *plpgsql_parse_wordrowtype(char *ident);
>      >   extern PLpgSQL_type *plpgsql_parse_cwordrowtype(List *idents);
>      >   extern PLpgSQL_type *plpgsql_build_datatype(Oid typeOid, int32
>     typmod,
>
>     By the way, these functions are misnamed after this patch.  They are
>     called "wordtype" and "cwordtype" originally because they accept
>     "word%TYPE" and "compositeword%TYPE", but after the patch they not only
>     accept TYPE at the right of the percent sign but also ELEMENTTYPE and
>     ARRAYTYPE.  Not sure that this is something we want to be too strict
>     about.
>
>
> Understand - used name ***reftype instead ****type

I am not sure, but it seems that new names is a little worse. I think 
original names are good too. They accept a word and return the 
PLpgSQL_type structure.

>
> Thank you for your comment
>
> Attached updated patch
>
> Regards
>
> Pavel
>
>
>
>     --
>     Álvaro Herrera http://www.2ndQuadrant.com/
>     PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>
>

I noticed a little typo in the comment in the derive_type():
/* Return base_type, when it is a array already */

should be:
/* Return base_type, when it is an array already */

-- 
Artur Zakirov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company



pgsql-hackers by date:

Previous
From: Simon Riggs
Date:
Subject: Re: Bug in StartupSUBTRANS
Next
From: Takashi Horikawa
Date:
Subject: Re: Typo in bufmgr.c that result in waste of memory