Re: SELECT syntax synopsis: column_definition? - Mailing list pgsql-sql

From Michael Glaesemann
Subject Re: SELECT syntax synopsis: column_definition?
Date
Msg-id CE1E5560-D185-48F2-BE12-97D837882D56@seespotcode.net
Whole thread Raw
In response to Re: SELECT syntax synopsis: column_definition?  (Michael Glaesemann <grzm@seespotcode.net>)
List 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




pgsql-sql by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: SELECT syntax synopsis: column_definition?
Next
From: Gregory Stark
Date:
Subject: Re: SELECT syntax synopsis: column_definition?