X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 84855D1B518 for ; Tue, 21 Oct 2003 18:57:52 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 27908-06 for ; Tue, 21 Oct 2003 15:57:21 -0300 (ADT) Received: from anchor-post-33.mail.demon.net (anchor-post-33.mail.demon.net [194.217.242.91]) by svr1.postgresql.org (Postfix) with ESMTP id 3F120D1B52D for ; Tue, 21 Oct 2003 15:57:20 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-33.mail.demon.net with esmtp (Exim 3.35 #1) id 1AC1h2-0009wy-0X; Tue, 21 Oct 2003 19:57:20 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 6B5641791B; Tue, 21 Oct 2003 19:57:19 +0100 (BST) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id C03181791A; Tue, 21 Oct 2003 19:57:18 +0100 (BST) From: Richard Huxton To: jclaudio@capitol.fr, pgsql-sql@postgresql.org Subject: Re: how to create a multi columns return function ? Date: Tue, 21 Oct 2003 19:57:17 +0100 User-Agent: KMail/1.5 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200310211957.17282.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/276 X-Sequence-Number: 15676 On Tuesday 21 October 2003 14:08, jclaudio@capitol.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