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

Re: allowed variable names in functions?

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: allowed variable names in functions?
Date: 2008-06-30 10:48:04
Message-ID: 20080630104804.GF13270@a-kretschmer.de (view raw or flat)
Thread:
Lists: pgsql-general
am  Mon, dem 30.06.2008, um 12:38:40 +0200 mailte A B folgendes:
> Then my assumption was wrong.
> Here is the entire function and it fails with the names
> c2,c2div,c3,c3div, but if names are changed, it works!
> (by works I mean I get the "hello" lines printed) There is nothing
> wrong with the select statement either, that works fine if I run it
> stand-alone, or with the names of c2,c2div,c3,c3div changed.
> 
> CREATE OR REPLACE FUNCTION foo(pid_ INTEGER) RETURNS void AS $$
> DECLARE
> 	c2 REAL;
> 	c2div REAL;
> 	c3 REAL;
> 	c3div REAL;
> 	weights RECORD;
> 	tmp RECORD;
> 	retval RECORD;
> 	t RECORD;
> BEGIN
> RAISE NOTICE 'starting...';
> 	FOR tmp IN SELECT id,c2,c3 FROM Master  WHERE pid=pid_  AND c3 !=0 LOOP
> 		RAISE NOTICE 'hello %',tmp.id;
> 	END LOOP;
> 	RETURN;
> END; $$  LANGUAGE plpgsql;

Don't use the same names for plpgsql-variables and for column names.


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

In response to

Responses

pgsql-general by date

Next:From: Pavel StehuleDate: 2008-06-30 10:48:14
Subject: Re: allowed variable names in functions?
Previous:From: A BDate: 2008-06-30 10:44:31
Subject: Re: allowed variable names in functions?

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