The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Special Forums > UNIX and Linux Applications
.
google unix.com



UNIX and Linux Applications Discuss UNIX and Linux software applications. This includes SQL, Databases, Middleware, MOM, SOA, EDA, CEP, BI, BPM and similar topics.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Return an array of strings from user defined function in awk user_prady Shell Programming and Scripting 2 12-04-2007 12:03 AM
need help with User Defined Function user_prady Shell Programming and Scripting 11 11-18-2007 08:51 PM
Very Strange Behavior for redirection cahook Shell Programming and Scripting 5 08-08-2007 11:32 AM
Nawk user-defined function NewbieGirl Shell Programming and Scripting 1 06-20-2003 10:51 AM
strange sed behavior Kevin Pryke UNIX for Dummies Questions & Answers 5 06-13-2003 04:34 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-24-2009
thegeek thegeek is offline
Registered User
  
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 436
strange behavior of PSQL user defined function

Segregated the problematic portion, and showing for your view here.,

1. Following is the function definition,

Code:
create or replace function new_del(id integer) returns void as $$
begin
    raise info 'dollar :%',$1;
    delete from testing  where id=$1;
    end ;
$$
language 'plpgsql';
2. following is the table "testing" contains,
Code:
SELECT * from testing ;
 id
-----
 101
 102
 103
(3 rows)

3. When i call the function as
Code:
SELECT new_del('101');
INFO:  dollar :101
 new_del
---------

(1 row)
It deletes all the rows ! Why it is doing like this !

4. But when i change the name of the argument then the function behaves normally.

I changed the argument name "id" to id_field it behaved normally and deletes only the specified row.


Any help is appreciated.
  #2 (permalink)  
Old 04-28-2009
thegeek thegeek is offline
Registered User
  
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 436
My friend too tried finding solution, and found it.

It is,
Where ever the argument occurs, it is being replaced with the $ value. That is "id" is replaced with $1 in the query so the query becomes,
Code:
delete from testing where $1 = $1
So it deletes all the specified rows.
Thanks for all the people who tried to find the problem in it.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:35 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0