Re: PL/pgSQL: Incomplete item Allow handling of %TYPE arrays, e.g. tab.col%TYPE[]

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Quan Zongliang <quanzongliang(at)yeah(dot)net>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: Incomplete item Allow handling of %TYPE arrays, e.g. tab.col%TYPE[]
Date: 2023-11-23 19:39:38
Message-ID: CAFj8pRBouuBJsZUwhGcsGT53bDyXvXiCv7uapBDt7Fj2j2ghEw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

čt 23. 11. 2023 v 13:28 odesílatel Quan Zongliang <quanzongliang(at)yeah(dot)net>
napsal:

>
>
> On 2023/11/20 17:33, Pavel Stehule wrote:
>
> >
> >
> > I did some deeper check:
> >
> > - I don't like too much parser's modification (I am sending alternative
> > own implementation) - the SQL parser allows richer syntax, and for full
> > functionality is only few lines more
> Agree.
>
> >
> > - original patch doesn't solve %ROWTYPE
> >
> > (2023-11-20 10:04:36) postgres=# select * from foo;
> > ┌────┬────┐
> > │ a │ b │
> > ╞════╪════╡
> > │ 10 │ 20 │
> > │ 30 │ 40 │
> > └────┴────┘
> > (2 rows)
> >
> > (2023-11-20 10:08:29) postgres=# do $$
> > declare v foo%rowtype[];
> > begin
> > v := array(select row(a,b) from foo);
> > raise notice '%', v;
> > end;
> > $$;
> > NOTICE: {"(10,20)","(30,40)"}
> > DO
> >
> two little fixes
> 1. spelling mistake
> ARRAY [ icons ] --> ARRAY [ iconst ]
> 2. code bug
> if (!OidIsValid(dtype->typoid)) --> if (!OidIsValid(array_typeid))
>
>
> > - original patch doesn't solve type RECORD
> > the error message should be more intuitive, although the arrays of
> > record type can be supported, but it probably needs bigger research.
> >
> > (2023-11-20 10:10:34) postgres=# do $$
> > declare r record; v r%type[];
> > begin
> > v := array(select row(a,b) from foo);
> > raise notice '%', v;
> > end;
> > $$;
> > ERROR: syntax error at or near "%"
> > LINE 2: declare r record; v r%type[];
> > ^
> > CONTEXT: invalid type name "r%type[]"
> >
> Currently only scalar variables are supported.
> This error is consistent with the r%type error. And record arrays are
> not currently supported.
> Support for r%type should be considered first. For now, let r%type[]
> report the same error as record[].
> I prefer to implement it with a new patch.
>

ok

>
> > - missing documentation
> My English is not good. I wrote it down, please correct it. Add a note
> in the "Record Types" documentation that arrays and "Copying Types" are
> not supported yet.
>
> >
> > - I don't like using the word "partitioned" in the regress test name
> > "partitioned_table". It is confusing
> fixed
>

I modified the documentation a little bit - we don't need to extra propose
SQL array syntax, I think.
I rewrote regress tests - we don't need to test unsupported functionality
(related to RECORD).

- all tests passed

Regards

Pavel

>
> >
> > Regards
> >
> > Pavel

Attachment Content-Type Size
v20231123-0001-support-of-syntax-type-and-rowtype.patch text/x-patch 10.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2023-11-23 19:45:07 Re: Questions regarding Index AMs and natural ordering
Previous Message Tom Lane 2023-11-23 19:15:50 Re: Questions regarding Index AMs and natural ordering