agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedembedded composite types
3+ messages / 3 participants
[nested] [flat]
* embedded composite types
@ 2021-02-20 14:41 Arturo Guadagnin <tuirutuiru@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Arturo Guadagnin @ 2021-02-20 14:41 UTC (permalink / raw)
To: pgsql-sql@lists.postgresql.org <pgsql-sql@lists.postgresql.org>
I have defined a composite type containing attributes of an other composite type, e.g.
create type MyPoint as (
x int,
y int
);
create Type Point2 as (
pt1 MyPoint,
pt2 MyPoint
);
accessing the first level using the dot operator works flawlessly, e.g.
do $$
DECLARE
p MyPoint;
BEGIN
p.x := 1;
p.y := 2;
RAISE NOTICE 'p=%', p;
END;
$$
p=(1,2)
But trying to navigate further gives an error:
do $$
DECLARE
p Point2;
x int;
BEGIN
p.pt1 := (1,2);
p.pt2 := (3,4);
x := p.pt1.x;
END;
$$
[42P01] ERROR: missing FROM-clause entry for table "pt1"
Where: PL/pgSQL function inline_code_block line 8 at assignment
doing it in 2 separate steps works (but is not nice)
do $$
DECLARE
p Point2;
pt1 MyPoint;
x int;
BEGIN
p.pt1 := (1,2);
pt1 := p.pt1;
x := pt1.x;
END;
$$
I’m just wondering whether this is the expected behaviour or if there is any syntactical magic I’m not aware of ....
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: embedded composite types
@ 2021-02-20 15:07 David G. Johnston <david.g.johnston@gmail.com>
parent: Arturo Guadagnin <tuirutuiru@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: David G. Johnston @ 2021-02-20 15:07 UTC (permalink / raw)
To: Arturo Guadagnin <tuirutuiru@gmail.com>; +Cc: pgsql-sql@lists.postgresql.org <pgsql-sql@lists.postgresql.org>
On Saturday, February 20, 2021, Arturo Guadagnin <tuirutuiru@gmail.com>
wrote:
>
> I’m just wondering whether this is the expected behaviour or if there is
> any syntactical magic I’m not aware of ....
>
https://www.postgresql.org/docs/current/sql-expressions.html#FIELD-SELECTION
David J.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: embedded composite types
@ 2021-02-20 15:58 Tom Lane <tgl@sss.pgh.pa.us>
parent: David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 0 replies; 3+ messages in thread
From: Tom Lane @ 2021-02-20 15:58 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Arturo Guadagnin <tuirutuiru@gmail.com>; pgsql-sql@lists.postgresql.org <pgsql-sql@lists.postgresql.org>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Saturday, February 20, 2021, Arturo Guadagnin <tuirutuiru@gmail.com>
> wrote:
>> I’m just wondering whether this is the expected behaviour or if there is
>> any syntactical magic I’m not aware of ....
> https://www.postgresql.org/docs/current/sql-expressions.html#FIELD-SELECTION
Yeah. Also note that we only recently got around to fixing plpgsql
assignment to allow nested fields; that is
declare p Point2;
...
p.pt1.x = 42;
works in HEAD but not in any released version.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2021-02-20 15:58 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-02-20 14:41 embedded composite types Arturo Guadagnin <tuirutuiru@gmail.com>
2021-02-20 15:07 ` David G. Johnston <david.g.johnston@gmail.com>
2021-02-20 15:58 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox