473,394 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

doubt in update query inside a function

priyan
54
hi all,
I wrote a function in postgre to insert or update a row in to a table. In my function insert query is working fine but updation is not working please help me....

here is my function

Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE FUNCTION savequestionbank_quest(pquestionid integer, pquestionbankid integer, pquestion text, pquestionsno integer, pquestionhistory text, pquestionparameter text, pquestionsource text, pquestionbibliograph text)
  2. RETURNS integer AS
  3. $BODY$
  4. Declare questionid integer;
  5. Begin
  6.     if pquestionid=0 then
  7.         insert into questionbank_quest(questionbankid,question,questsno,questhistory,questparamet,questsource,questbibliograp)
  8.              values(pquestionbankid,pquestion,pquestionsno,pquestionhistory,pquestionparameter,pquestionsource,pquestionbibliograph);
  9.         questionid := lastval();
  10.     else 
  11.         update questionbank_quest set questionbankid=pquestionbankid,question=pquestion,questsno=pquestionsno,questhistory=pquestionhistory,
  12.             questparamet=pquestionparameter,questsource=pquestionsource,questbibliograp=pquestionbibliograph where questionid=pquestionid;
  13.          questionid = pquestionid;
  14.     end if;
  15. return questionid;
  16. End
  17. $BODY$
  18. LANGUAGE 'plpgsql' VOLATILE;
  19.  
Oct 18 '07 #1
2 3553
priyan
54
hi all,
I wrote a function in postgre to insert or update a row in to a table. In my function insert query is working fine but updation is not working please help me....

here is my function

Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE FUNCTION savequestionbank_quest(pquestionid integer, pquestionbankid integer, pquestion text, pquestionsno integer, pquestionhistory text, pquestionparameter text, pquestionsource text, pquestionbibliograph text)
  2. RETURNS integer AS
  3. $BODY$
  4. Declare questionid integer;
  5. Begin
  6.     if pquestionid=0 then
  7.         insert into questionbank_quest(questionbankid,question,questsno,questhistory,questparamet,questsource,questbibliograp)
  8.              values(pquestionbankid,pquestion,pquestionsno,pquestionhistory,pquestionparameter,pquestionsource,pquestionbibliograph);
  9.         questionid := lastval();
  10.     else 
  11.         update questionbank_quest set questionbankid=pquestionbankid,question=pquestion,questsno=pquestionsno,questhistory=pquestionhistory,
  12.             questparamet=pquestionparameter,questsource=pquestionsource,questbibliograp=pquestionbibliograph where questionid=pquestionid;
  13.          questionid = pquestionid;
  14.     end if;
  15. return questionid;
  16. End
  17. $BODY$
  18. LANGUAGE 'plpgsql' VOLATILE;
  19.  


Please help me to solve this problem function is running properly and also insertion is taking place but updation alone is not working. Table is not get updated i don't no why it is like this.............please help me to solve this problem...........As soon as possible..............
Oct 18 '07 #2
amitpatel66
2,367 Expert 2GB
Please help me to solve this problem function is running properly and also insertion is taking place but updation alone is not working. Table is not get updated i don't no why it is like this.............please help me to solve this problem...........As soon as possible..............
Can you make sure that the data for the pquestionid that is passed as input parameter exists in the table??

and use COMMIT with in the procedure after INSERT and UPDATE statement in order to COMMIT the changes that are made!!
Oct 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ken Bush | last post by:
How can I write an update query that removes part of a field? Like if I have a field with values such as 8/3/68 (a birthday obviously) and I need to put values in a new column but I need...
10
by: deko | last post by:
I've tried each of the below, but no luck. UPDATE tblEntity As tbl INNER JOIN search3220 As qry ON tbl.Entity_ID = qry.Entity_ID SET tbl.Cat_ID = 289; UPDATE tblEntity INNER JOIN search3220 ON...
3
by: | last post by:
Hi, I have a major problem. I use Windows 2000 highest SP and ACCESS 2000 inside Office 2000 SP-3. I want to use the following simple command inside ACCESS in VBA UPDATE tbl_SATURN_Benutzer...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
9
by: baonks | last post by:
hello all here is my problem: I have 2 table 1: K_POS SALDO_A_D SALDO_A_K 11100 105 5 11200 5 105
11
by: DFS | last post by:
Architecture: Access 2003 client, Oracle 9i repository, no Access security in place, ODBC linked tables. 100 or so users, in 3 or 4 groups (Oracle roles actually): Admins, Updaters and ReadOnly....
3
by: Greg Strong | last post by:
Hello All, Is the only solution to an update query which requires the records in a certain order to dump the records into a temp table in the required order, then do the update query? I've...
4
by: hapnendad | last post by:
In the question statement below Field names are in and variables are in (). All fields referenced are in what I have named the ‘PAR’ Table. Using MS Access 2003, I am working on a project...
1
by: giovannino | last post by:
Dear all, I did a query which update a sequence number (column NR_SEQUENZA) in a table using a nice code (from Trevor !). 1) Given that I'm not a programmer I can't understand why...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.