SELECT composite type

From: Michael Burke <michael(at)engtech(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: SELECT composite type
Date: 2006-04-05 15:57:09
Message-ID: 200604051257.09980.michael@engtech.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,

I have a function get_xy that returns a composite type with columns "x" and
"y". I would like to SELECT these as well as some data from a table, like
so:

SELECT
(get_xy(SetSRID(sightings.location, 26910), 4326)).x,
(get_xy(SetSRID(sightings.location, 26910), 4326)).y,
sightings.title
FROM sightings
WHERE sighting_id = 25;

This statement works, but I don't want to duplicate the function call as this
should be unnecessary. Selecting simply get_xy returns both fields in a
single column, which is undesirable.

I tried:

SELECT foo.x, foo.y, sightings.title
FROM sightings, get_xy(SetSRID(sightings.location, 26910), 4326) foo
WHERE sighting_id = 25;

But, because the function refers to sightings, I get this error:
ERROR: function expression in FROM may not refer to other relations of same
query level

...which is reasonable. So I basically want to call get_xy for every row in
sightings, and use its output for two columns; or perhaps there is another
way to think of this.

I am using Postgres 8.1.2 (same with client) on FreeBSD, with PostGIS 1.1.1:
$ postmaster --version
postmaster (PostgreSQL) 8.1.2

Thanks in advance!
Mike.

--
Michael Burke
Engineering Technologies Canada Ltd. - http://www.engtech.ca/
michael(at)engtech(dot)ca 1 (902) 628-1705

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Renato Cramer 2006-04-05 16:45:25 IF statement in Select
Previous Message Stephan Szabo 2006-04-05 14:36:46 Re: have you feel anything when you read this ?