Search Postgresql Archives

PLPGSQL: when the local variable used and when the table field?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello!

PLPGSQL allows me to write simple queries and updates without execute + using.

F.e:
DECLARE t text; anytype text;
BEGIN
...
  select nev into t from anytable where type = anytype;
...
  insert into bla (id, name, type)
  select id, name, anytype from bla
...

But this method is seems to be unsafe  for me.
How the compiler knows what value I want to use?

If bla table has "anytype" field, it can use that field, or it can use local variable too.
Which has more priority/precedency?

For example:
1.) I have this proc (installed):
select nev into t from anytable where type = anytype;
Later I add anytype column to anytable.

2.) Or this:
  insert into bla (id, name, type)
  select id, name, anytype from bla
Later I add anytype to bla.

What would happen? 
The working procedure makes error, because it have more possible source of data (local variable, and table field)?
Or it uses the local variable, because in the scope it has more precedency?

Ok, sometimes I can use prefix for table:
  select bla.id, bla.name, anytype from bla  

But when I WANT to use local variable (as constant) and later the bla extended with anytype column, it would be source of conflict.

Somewhere I force to use "_" prefix for local variables to be sure in result.

Do you know any info about the background?

Thanks for answer!

Best  regards

   dd
 

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux