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

Functions

From: Nick Jones <neckjonez(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Functions
Date: 2005-05-26 20:07:36
Message-ID: be08207005052613076f4c638c@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
All,

I'm trying to figure out how functions work in PGSQL. I've got a sample here 
but I keep getting an error and I'm not sure why.

CREATE FUNCTION test2(VARCHAR) RETURNS SETOF TEXT AS 
'
DECLARE
r record;
BEGIN
FOR r IN 
select router_name from router where router_name ~ $1
LOOP
RETURN NEXT r;
END LOOP;
RETURN;
END;
' LANGUAGE 'plpgsql';

Then when I run this command:
select * from test2('houston');

I get an error:
WARNING: Error occurred while executing PL/pgSQL function test2
WARNING: line 7 at return next
ERROR: Attribute "r" not found

I'm not sure why I get this error, i thought I declared it in the declare 
section.

-- 
Thanks,
Nick

Responses

pgsql-novice by date

Next:From: operationsengineer1Date: 2005-05-26 20:16:44
Subject: Carriage Returns Disappearing
Previous:From: David SadlerDate: 2005-05-26 17:21:35
Subject: ERROR: relation "default_cols" does not exist

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group