Обсуждение: Local variable and column name conflict

Поиск
Список
Период
Сортировка

Local variable and column name conflict

От
"Daniel Caune"
Дата:
Hi,

Is there a way to specify a local variable/parameter within a query
where a column has the same name than the local variable/parameter?

Example:

CREATE OR REPLACE FUNCTION foo(i IN int) RETURNS void
AS $$
BEGIN UPDATE bar   SET i = i; // column i = parameter i
END;
$$ LANGUAGE PLPGSQL;

For instance, Ingres suggests prefixing local variable/parameter with
":" in the query:
 UPDATE bar   SET i = :i;

I can continue using the de facto Oracle's naming convention
(P_parameter and V_local_variable) anyway.  That's not a big deal.

Regards,

--
Daniel CAUNE
Ubisoft Online Technology
(514) 490 2040 ext. 3613


Re: Local variable and column name conflict

От
Tom Lane
Дата:
"Daniel Caune" <daniel.caune@ubisoft.com> writes:
> CREATE OR REPLACE FUNCTION foo(i IN int)
>   RETURNS void
> AS $$
> BEGIN
>   UPDATE bar
>     SET i = i; // column i = parameter i
> END;
> $$ LANGUAGE PLPGSQL;

In SELECTs you can qualify the column, ie, bar.i vs i.  That doesn't
work for an UPDATE target, though, so probably the best answer is
"don't do that".  I think it's entirely too error-prone anyway ...
        regards, tom lane