Re: SELECT syntax synopsis: column_definition?

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Michael Glaesemann <grzm(at)seespotcode(dot)net>
Cc: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>, SQL Postgresql List <pgsql-sql(at)postgresql(dot)org>
Subject: Re: SELECT syntax synopsis: column_definition?
Date: 2007-08-21 23:17:17
Message-ID: CE1E5560-D185-48F2-BE12-97D837882D56@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Aug 21, 2007, at 18:04 , Michael Glaesemann wrote:

> So the *form* is right, but I don't know of an example that works.

CREATE TABLE foos
(
foo text PRIMARY KEY
, title text NOT NULL
);

INSERT INTO foos (foo, title) values
('foo', 'the great')
, ('bar', 'the extravagant')
, ('baz', 'the indisputable');

CREATE OR REPLACE FUNCTION get_foo() RETURNS record
LANGUAGE plpgsql AS $body$
DECLARE
v_record record;
BEGIN
SELECT INTO v_record
*
FROM foos
ORDER BY RANDOM()
LIMIT 1;
RETURN v_record;
END;
$body$;

a | b
-----+------------------
baz | the indisputable
(1 row)

test=# SELECT *
test-# FROM get_foo() AS (a text, b text);
a | b
-----+-----------------
bar | the extravagant
(1 row)

IIRC, this form is used by the crosstab functions in tablefunc.

Michael Glaesemann
grzm seespotcode net

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Gregory Stark 2007-08-21 23:53:21 Re: SELECT syntax synopsis: column_definition?
Previous Message Michael Glaesemann 2007-08-21 23:04:56 Re: SELECT syntax synopsis: column_definition?