0xAX
0xAX

Reputation: 21817

Return setof varchar

I have PostgreSQL table. I need in function which returns setof varchar. My table:

create table my_table (
    str varchar not null
)

How can I write a function that returns a set of str field?

Upvotes: 0

Views: 1001

Answers (1)

Erwin Brandstetter
Erwin Brandstetter

Reputation: 656636

Basic example with LANGUAGE SQL:

CREATE OR REPLACE FUNCTION foo()
  RETURNS SETOF varchar
  LANGUAGE SQL AS
$BODY$
    SELECT str
    FROM   my_table
    WHERE  <some condition>;
$BODY$;

Call:

SELECT * FROM foo();

Start by reading the basics in the manual.

Upvotes: 1

Related Questions