From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Lorusso Domenico <domenico.l76@gmail.com>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: select from composite type
Date: Mon, 5 Feb 2024 16:41:51 -0800
Message-ID: <ee75f42f-2741-4b76-bb44-8c40872859b8@aklaver.com> (raw)
In-Reply-To: <CAJMpnG43yj6KVEXe2sLfXGpNSk0ydyR0_kcsXrxqeo1x-k5xxA@mail.gmail.com>
References: <CAJMpnG4nv+itZ8SA5R0MPevOtnzkNaRhCuFcZk+hZR7UzHdD9g@mail.gmail.com>
<3c650059-4d07-461c-a791-3f73338a9acc@aklaver.com>
<CAKFQuwbgspq1_jRD=zoB-k+NOJ4v0D3_XRFihGW5egcJB-u56Q@mail.gmail.com>
<CAJMpnG7qgcVr3qoQWZnps39oYu7=t33HpUDGVjen4Lau83y41Q@mail.gmail.com>
<CAJMpnG43yj6KVEXe2sLfXGpNSk0ydyR0_kcsXrxqeo1x-k5xxA@mail.gmail.com>
On 2/5/24 16:35, Lorusso Domenico wrote:
> ah ehm.. I solved, it was very easy but I believed it should use the
> from clause...
>
> execute 'select ($1).* ' using _attribute into _r;
Beat me to it
For the reason why it works:
https://www.postgresql.org/docs/current/sql-expressions.html#SQL-SYNTAX-ROW-CONSTRUCTORS>
> Il giorno mar 6 feb 2024 alle ore 01:01 Lorusso Domenico
> <domenico.l76@gmail.com <mailto:domenico.l76@gmail.com>> ha scritto:
>
> here an example (the actual case in more complex, but the point it's
> the same)
>
> do $$
> declare
> _attribute_list temp1.my_type[];
> _attribute temp1.my_type;
>
> _r record;
> begin
> _attribute_list=array[row(1,'Hello') , row(2,'Goodbye')];
>
> _attribute= row(1,'Doh!!!!');
>
> raise notice '%', _attribute_list;
>
> for _r in execute 'select * from unnest($1) where foo=1' using
> _attribute_list loop
> raise notice '%', _r;
> end loop;
>
> --Error
> execute 'select * from $1' using _attribute into _r;
>
> raise notice '%', _r;
> end;
> $$;
>
> So I able to manage an array of complex type (why I use an array,
> because in a previous answer the community suggest to me to use
> an array to pass a list of information instead of temporary table),
> but I can't do the same thing with just an element.
>
> Of course I can set an element as part of an array with just that
> element but. it's sad...
>
>
> Il giorno lun 5 feb 2024 alle ore 01:48 David G. Johnston
> <david.g.johnston@gmail.com <mailto:david.g.johnston@gmail.com>> ha
> scritto:
>
> On Sun, Feb 4, 2024 at 5:39 PM Adrian Klaver
> <adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>>
> wrote:
>
>
> >
> > attribute_list is an array of composite type (with 20
> fields).
>
> I am trying to wrap my head around "array of composite
> type". Please
> provide an example.
>
>
> ARRAY[ (1,2)::point, (3,4)::point ]::point[]
>
> The main problem is the concept of writing "from($1)" in any
> query makes no sense, you cannot parameterize a from clause
> directly like that. You have to put the value somewhere an
> expression is directly allowed.
>
> David J.
>
>
>
> --
> Domenico L.
>
> per stupire mezz'ora basta un libro di storia,
> io cercai di imparare la Treccani a memoria... [F.d.A.]
>
>
>
> --
> Domenico L.
>
> per stupire mezz'ora basta un libro di storia,
> io cercai di imparare la Treccani a memoria... [F.d.A.]
--
Adrian Klaver
adrian.klaver@aklaver.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, domenico.l76@gmail.com, david.g.johnston@gmail.com
Subject: Re: select from composite type
In-Reply-To: <ee75f42f-2741-4b76-bb44-8c40872859b8@aklaver.com>
References: <CAJMpnG4nv+itZ8SA5R0MPevOtnzkNaRhCuFcZk+hZR7UzHdD9g@mail.gmail.com> <3c650059-4d07-461c-a791-3f73338a9acc@aklaver.com> <CAKFQuwbgspq1_jRD=zoB-k+NOJ4v0D3_XRFihGW5egcJB-u56Q@mail.gmail.com> <CAJMpnG7qgcVr3qoQWZnps39oYu7=t33HpUDGVjen4Lau83y41Q@mail.gmail.com> <CAJMpnG43yj6KVEXe2sLfXGpNSk0ydyR0_kcsXrxqeo1x-k5xxA@mail.gmail.com> <ee75f42f-2741-4b76-bb44-8c40872859b8@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox