agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Arturo Guadagnin <tuirutuiru@gmail.com>
To: pgsql-sql@lists.postgresql.org <pgsql-sql@lists.postgresql.org>
Subject: embedded composite types
Date: Sat, 20 Feb 2021 15:41:09 +0100
Message-ID: <60311f89.1c69fb81.3220e.2fd4@mx.google.com> (raw)

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 ....

view thread (3+ messages)  latest in thread

Message-ID: <60311f89.1c69fb81.3220e.2fd4@mx.google.com>
Permalink:  ../60311f89.1c69fb81.3220e.2fd4@mx.google.com/
Also on:    postgresql.org/message-id/60311f89.1c69fb81.3220e.2fd4@mx.google.com

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tuirutuiru@gmail.com, pgsql-sql@lists.postgresql.org
  Subject: Re: embedded composite types
  In-Reply-To: <60311f89.1c69fb81.3220e.2fd4@mx.google.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox