Search Postgresql Archives

Re: deleting function

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

 



On Fri, Apr 24, 2009 at 08:19:37PM -0700, pavunkumar wrote:
> On Apr 24, 8:55 pm, t...@xxxxxxxxxxxxx (Tom Lane) wrote:
> > Don't use the same name for a parameter as you use for a table column
> > referenced in the function.  The above is equivalent to
> > "delete... where $1=$1", ie, delete everything.
> 
> Whatever your saying right , But why the function not saying error....
> ? that is my doubt... this is what I want to clarify....!

This is the same as most imperative programming languages; for example
in C:

  {
    int id = 1;
    {
      int id = 5;
      printf ("id = %i\n", id);
    }
    printf ("id = %i\n", id);
  }

Will print out 5 followed 1.  In C it was considered useful to allow
inner blocks of code to have variables of the same name as outer blocks
and the actual name resolution would proceed from the inner-most block
outwards until a matching definition is found.  This convention was
invented before C and is used in most languages I'm aware of.

PL/pgSQL follows a similar convention; unqualified names are looked
up first against the function's parameters and then defaults back to
looking for column names.  It could be argued that it would be nice if
you got an error in the case of ambiguity like above, but PG doesn't
currently do that.

If you'd written your delete command as:

  DELETE FROM testing WHERE testing.id = id;

or better:

  DELETE FROM testing t WHERE t.id = id;

then it would do what you're expecting.

Hope that helps

-- 
  Sam  http://samason.me.uk/

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[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