From: | Richard Huxton <dev(at)archonet(dot)com> |
---|---|
To: | jclaudio(at)capitol(dot)fr, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: how to create a multi columns return function ? |
Date: | 2003-10-21 18:57:17 |
Message-ID: | 200310211957.17282.dev@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Tuesday 21 October 2003 14:08, jclaudio(at)capitol(dot)fr wrote:
> Hi
>
> I'm moving databases from sybase to postgres.
> But I have difficulties in creating a postgres equivalent to the sybase
> stored procedures...
>
> Apparently, Postgres functions should work, but the syb stored procedures
> get only one parameter and return several colums
>
> Here's the code I wrote in postgresql :
>
> create function function_name( int ) returns text
> AS ' SELECT column1, column2, column3,...,column15
You've said it's returning "text" whereas it's returning whatever your columns
are. You'll want to do something like:
CREATE TYPE fn_ret_type AS (
column1 int4,
column2 text,
column3 date,
...
);
CREATE FUNCTION function_name(int) RETURNS fn_ret_type ...
If it returns multiple rows you want SETOF fn_ret_type
--
Richard Huxton
Archonet Ltd
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2003-10-21 18:59:18 | Re: Writing the SQL queries inside Functions and operators |
Previous Message | Richard Huxton | 2003-10-21 18:54:30 | Re: plpgsql related question: intervals and variables |