unique names in variables and columns in plsql functions - Mailing list pgsql-sql

From Wiebe Cazemier
Subject unique names in variables and columns in plsql functions
Date
Msg-id 4427F7D3.3000103@gmail.com
Whole thread Raw
Responses Re: unique names in variables and columns in plsql functions
Re: unique names in variables and columns in plsql functions
List 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?

pgsql-sql by date:

Previous
From: John DeSoi
Date:
Subject: Re: Problem using set-returning functions
Next
From: "Jim C. Nasby"
Date:
Subject: Re: unique names in variables and columns in plsql functions