strange behavior of PSQL user defined function

 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications strange behavior of PSQL user defined function
# 1  
Old 04-24-2009
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  
Old 04-28-2009
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Call user defined function from awk

My requirement is to call function ("fun1") from awk, and print its returned value along with $0. fun1() { t=$1 printf "%02d\n", $t % 60; } echo "Hi There 23" | awk '{print $0; system(fun1 $3)}' Any suggestions what to be modified in above code to achieve requirement.. (5 Replies)
Discussion started by: JSKOBS
5 Replies

2. UNIX for Dummies Questions & Answers

Problem syntax with user-defined function

Hi ! I got a script from Arabic to Roman numeral conversion - .comp.lang.awk, that I would like to modify to apply it on my input file. input ("|"-delimited fields): AAAAAA|1, 10, 13, 14, 25, 60 wanted output: AAAAAA|I, X, XIII, XIV, XXV, LX script.awk: #!/usr/bin/gawk -f ... (11 Replies)
Discussion started by: lucasvs
11 Replies

3. Red Hat

strange mail behavior

Hi I have script to to take backup and send mail to a group once a day. One strange behavior I have observed recently is that most of the time the mail we receive is fine . But someday it just sends out mail without any subject with undisclosed recipients. I dont know how to find the cause... (0 Replies)
Discussion started by: ningy
0 Replies

4. Shell Programming and Scripting

How to pass parameter to User defined function in shell script?

Hello, Can anyone guide me tin passing parameters into user defined function of shell script (KSH). Here is my code, InsertRecord() { DB_TBL=$(sqlplus $USERID/$PASSWORD@$DATABASE << EOF set head off set feed off set serveroutput on INSERT INTO TBL1 ( OLD_VAL, NEW_VAL, ... (7 Replies)
Discussion started by: Poonamol
7 Replies

5. Programming

Strange behavior in C++

I have the following program: int main(int argc, char** argv){ unsigned long int mean=0; for(int i=1;i<10;i++){ mean+=poisson(12); cout<<mean<<endl; } cout<<"Sum of poisson: "<< mean; return 0; } when I run it, I get the... (4 Replies)
Discussion started by: santiagorf
4 Replies

6. Shell Programming and Scripting

Return an array of strings from user defined function in awk

Hello Friends, Is it possible to return an array from a user defined function in awk ? example: gawk ' BEGIN{} { catch_line = my_function(i) print catch_line print catch_line print catch_line } function my_function(i) { print "echo" line= "awk" line= "gawk"... (2 Replies)
Discussion started by: user_prady
2 Replies

7. Shell Programming and Scripting

need help with User Defined Function

Dear Friends, I need a help regarding User defined function in shell script. My problem is as follows: my_func.sh my_funcI(){ grep 'mystring' I.dat } my_funcQ(){ grep 'mystring' Q.dat } myfuncI myfuncQ But As both the function has same function only the... (11 Replies)
Discussion started by: user_prady
11 Replies

8. UNIX for Dummies Questions & Answers

Strange Behavior on COM2

Hi, I have a problem with a new touch screen controller that I am trying to use on a SCO 3.0 system. THe touch screen controller only wants to talk at 9600baud. I have updated /etc/inittab per the manual and also edited /usr/lib/event/devices to use 9600 baud. The only way I can get the... (0 Replies)
Discussion started by: Elwood51
0 Replies

9. Shell Programming and Scripting

Nawk user-defined function

HELP!!!! I am in an on-line shell programming class and have a question. Here is the data: Mike Harrington:(510) 548-1278:250:100:175 Christian Dobbins:(408) 538-2358:155:90:201 Susan Dalsass:(206) 654-6279:250:60:50 (There are 12 contribuors total) This database contains names, phone... (1 Reply)
Discussion started by: NewbieGirl
1 Replies
Login or Register to Ask a Question