unique names in variables and columns in plsql functions

From: Wiebe Cazemier <halfgaar(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: unique names in variables and columns in plsql functions
Date: 2006-03-27 14:33:55
Message-ID: 4427F7D3.3000103@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

In a plpgsl function, consider the following excerpt:

DECLARE
provider_id INTEGER;
BEGIN
provider_id := (SELECT provider_id FROM investment_products WHERE id =
my_new.investment_product_id);
END;

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?

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jim C. Nasby 2006-03-27 14:48:04 Re: unique names in variables and columns in plsql functions
Previous Message John DeSoi 2006-03-27 14:30:36 Re: Problem using set-returning functions