From: Michael Glaesemann <grzm@seespotcode.net>
To: Michael Glaesemann <grzm@seespotcode.net>
Cc: Richard Broersma Jr <rabroersma@yahoo.com>
Cc: SQL Postgresql List <pgsql-sql@postgresql.org>
Subject: Re: SELECT syntax synopsis: column_definition?
Date: Tue, 21 Aug 2007 18:17:17 -0500
Message-ID: <CE1E5560-D185-48F2-BE12-97D837882D56@seespotcode.net> (raw)
In-Reply-To: <50700110-2B0D-4935-B033-084ED908BEC5@seespotcode.net>
References: <830878.14424.qm@web31803.mail.mud.yahoo.com>
<50700110-2B0D-4935-B033-084ED908BEC5@seespotcode.net>
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
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: grzm@seespotcode.net, rabroersma@yahoo.com
Subject: Re: SELECT syntax synopsis: column_definition?
In-Reply-To: <CE1E5560-D185-48F2-BE12-97D837882D56@seespotcode.net>
* 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