Skip site navigation (1) Skip section navigation (2)

Re: User defined types

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Reza Shanbehbazari Mirzaei <mirzaei(at)stud(dot)ntnu(dot)no>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: User defined types
Date: 2004-11-25 18:29:42
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
Reza Shanbehbazari Mirzaei <mirzaei(at)stud(dot)ntnu(dot)no> writes:
>   I have a user define type called VALID_TIME. It is declared as follows:


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

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

In response to

pgsql-sql by date

Next:From: Andrew MDate: 2004-11-25 18:43:29
Subject: HowTo change encoding type....
Previous:From: Michael FuhrDate: 2004-11-24 19:53:27
Subject: Re: Explicitly rolling back transaction from within a C-Language function

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group