pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Reza Shanbehbazari Mirzaei <mirzaei@stud.ntnu.no>
Cc: pgsql-sql@postgresql.org
Subject: Re: User defined types
Date: Thu, 25 Nov 2004 13:29:42 -0500
Message-ID: <1114.1101407382@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.LNX.4.58.0411201729220.32082@jaguar.stud.ntnu.no>
References: <Pine.LNX.4.58.0411201729220.32082@jaguar.stud.ntnu.no>

Reza Shanbehbazari Mirzaei <mirzaei@stud.ntnu.no> writes:
>   I have a user define type called VALID_TIME. It is declared as follows:

>   CREATE TYPE VALID_TIME AS (t_s TIMESTAMP, t_e TIMESTAMP);

>   Once I have used this in a table declaration, is it possible to extract
> parts of it, for example to only read t_s or t_e? If so, how do I do this?

8.0 supports using composite types as table columns, but prior versions
don't really.  In 8.0 you'd do something like

	create table myt (vt valid_time);

	select (vt).t_s from myt;
or
	select (myt.vt).t_s from myt;

The parentheses are essential --- without them, you'd have for instance

	select vt.t_s from myt;

which looks like a reference to field t_s of table vt, not what you
want.

You can hack around the problem in earlier versions by creating helper
functions, eg

	select get_t_s(vt) from myt;

but it's ugly enough to make one wonder why bother with a composite type.

			regards, tom lane



view thread (2+ messages)

Message-ID: <1114.1101407382@sss.pgh.pa.us>
Permalink:  ../1114.1101407382@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1114.1101407382@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, mirzaei@stud.ntnu.no
  Subject: Re: User defined types
  In-Reply-To: <1114.1101407382@sss.pgh.pa.us>

* 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