pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedLocal variable and column name conflict
2+ messages / 2 participants
[nested] [flat]
* Local variable and column name conflict
@ 2006-07-03 15:34 Daniel Caune <daniel.caune@ubisoft.com>
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Caune @ 2006-07-03 15:34 UTC (permalink / raw)
To: pgsql-sql
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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Local variable and column name conflict
@ 2006-07-03 15:37 Tom Lane <tgl@sss.pgh.pa.us>
parent: Daniel Caune <daniel.caune@ubisoft.com>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2006-07-03 15:37 UTC (permalink / raw)
To: Daniel Caune <daniel.caune@ubisoft.com>; +Cc: pgsql-sql
"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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2006-07-03 15:37 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-07-03 15:34 Local variable and column name conflict Daniel Caune <daniel.caune@ubisoft.com>
2006-07-03 15:37 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox