On Mon, Mar 27, 2006 at 04:33:55PM +0200, Wiebe Cazemier wrote:
> In a plpgsl function, consider the following excerpt:
> provider_id INTEGER;
> provider_id := (SELECT provider_id FROM investment_products WHERE id =
> After a lot of trouble, I found out this line doesn't work correctly
> with the variable name as it is. It doesn't give an error or anything,
> it just retrieves some wrong value (probably NULL). When I change the
> variable name to anything other than "provider_id", it works OK.
> I was somewhat surprised to discover this. Can't Postgres determine that
> the provider_id in the SELECT statement is not the same one as the variable?
Sadly, overloading variable names between plpgsql and SQL is *highly*
problematic. Because of this I *always* prefix plpgsql variables with
something, such as p_ for parameters and v_ for general variables.
Jim C. Nasby, Sr. Engineering Consultant jnasby(at)pervasive(dot)com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461
In response to
pgsql-sql by date
|Next:||From: Markus Schaber||Date: 2006-03-27 14:51:51|
|Subject: Re: pgsql2shp - Could not create dbf file|
|Previous:||From: Wiebe Cazemier||Date: 2006-03-27 14:33:55|
|Subject: unique names in variables and columns in plsql functions|