Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Return rows from function with expressions


  • From: novnov <novnovice(at)gmail(dot)com>
  • To: pgsql-general(at)postgresql(dot)org
  • Subject: Return rows from function with expressions
  • Date: Thu, 24 May 2007 13:59:24 -0700 (PDT)
  • Message-id: <10792602(dot)post(at)talk(dot)nabble(dot)com>

I've written many stored procedures in ms sql and a good many functions in
postgres, but I'm rather unsure of how to get a list back from a postgres
function which is not based on a table. Example from sql server:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[procPatient] 
	@PatStatusID int = 0 
AS
BEGIN
	SELECT PatID, PatFName + ' ' + PatLName as pname  FROM tblPatient WHERE
PatStatusID = @PatStatusID
END

Output from the sproc above is like 
PatID  pname
123    Merton Baffled
129    Jim Puzzled

I've spent a good deal of time reading here and in the pg docs about
functions that use SETOF. I can't find a plain and simple way to do
something like the above. Is there? I simply need to pass in some params,
and do some evals inside the function and return a set that includes some
cols that are not part of the base table. I've seen solutions that involve
OUT params; a method which uses RECORD that requires the columns to be
defined in the call; refcursors (which I don't really understand); are those
the only options? A simple example like the one I've used for sql server
above would be ideal.
-- 
View this message in context: http://www.nabble.com/Return-rows-from-function-with-expressions-tf3812759.html#a10792602
Sent from the PostgreSQL - general mailing list archive at Nabble.com.




Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group