Re: [GENERAL] trigger and plpgsq help needed

2012-09-27 Thread SUNDAY A. OLUTAYO
Thanks you all, 

" IF last_id IS NULL THEN " eventually work 


Thanks, 

Sunday Olutayo 
Sadeeb Technologies Ltd 


- Original Message -

From: "SUNDAY A. OLUTAYO"  
To: "Rob Richardson"  
Cc: pgsql-general@postgresql.org 
Sent: Thursday, September 27, 2012 2:04:46 PM 
Subject: Re: [GENERAL] trigger and plpgsq help needed 


RobR, 

I have tried it 'IF FOUND' but not getting the desired result 


Thanks, 

Sunday Olutayo 


- Original Message -

From: "Rob Richardson"  
To: pgsql-general@postgresql.org 
Sent: Wednesday, September 26, 2012 7:14:46 PM 
Subject: Re: [GENERAL] trigger and plpgsq help needed 



Why not use IF FOUND? 

RobR 



From: pgsql-general-ow...@postgresql.org 
[mailto:pgsql-general-ow...@postgresql.org] On Behalf Of SUNDAY A. OLUTAYO 
Sent: Wednesday, September 26, 2012 12:43 PM 
To: pgsql-general@postgresql.org 
Subject: [GENERAL] trigger and plpgsq help needed 


Dear all, 

I have issue with the red portion function below; 

This IF last_id IS NULL THEN suppose to test if last_id is NULL, that is the 
select query did not found it 
then execute the rest of the red sql but it always fail to insert the 
NEW.amount into amount , every other things fine. 

Kindly help out. 





Re: [GENERAL] trigger and plpgsq help needed

2012-09-27 Thread SUNDAY A. OLUTAYO
I have tried "IF NOT FOUND THEN" but not getting the desired result

Thanks, 

Sunday Olutayo 
Sadeeb Technologies Ltd 
7 Mayegun Street, Ojo 
Lagos State, Nigeria. 

Tel: +234 1 7404524 
D/L: +234 1 8169922 
Cell: +234 8054600338, 234 8096441688 
Fax: +234 8054895664 
mail: olut...@sadeeb.com 




- Original Message -
From: "Chris Ernst" 
To: pgsql-general@postgresql.org
Sent: Wednesday, September 26, 2012 7:10:03 PM
Subject: Re: [GENERAL] trigger and plpgsq help needed

On 09/26/2012 10:42 AM, SUNDAY A. OLUTAYO wrote:
> This IF last_id IS NULL THEN suppose to test if last_id is NULL, that is
> the select query did not found it
> then execute the rest of the red sql but it always fail to insert the
> *NEW.amount *into*amount*, every other things fine.

I believe what you're looking for is "IF NOT FOUND THEN" instead of "IF
last_id IS NULL THEN"

Cheers!

- Chris



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


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


Re: [GENERAL] trigger and plpgsq help needed

2012-09-27 Thread SUNDAY A. OLUTAYO
RobR, 

I have tried it 'IF FOUND' but not getting the desired result 


Thanks, 

Sunday Olutayo 


- Original Message -

From: "Rob Richardson"  
To: pgsql-general@postgresql.org 
Sent: Wednesday, September 26, 2012 7:14:46 PM 
Subject: Re: [GENERAL] trigger and plpgsq help needed 



Why not use IF FOUND? 

RobR 



From: pgsql-general-ow...@postgresql.org 
[mailto:pgsql-general-ow...@postgresql.org] On Behalf Of SUNDAY A. OLUTAYO 
Sent: Wednesday, September 26, 2012 12:43 PM 
To: pgsql-general@postgresql.org 
Subject: [GENERAL] trigger and plpgsq help needed 


Dear all, 

I have issue with the red portion function below; 

This IF last_id IS NULL THEN suppose to test if last_id is NULL, that is the 
select query did not found it 
then execute the rest of the red sql but it always fail to insert the 
NEW.amount into amount , every other things fine. 

Kindly help out. 




Re: [GENERAL] trigger and plpgsq help needed

2012-09-26 Thread Adrian Klaver

On 09/26/2012 09:42 AM, SUNDAY A. OLUTAYO wrote:

Dear all,

I have issue with the red portion function below;

This IF last_id IS NULL THEN suppose to test if last_id is NULL, that is
the select query did not found it
then execute the rest of the red sql but it always fail to insert the
*NEW.amount *into*amount*, every other things fine.


Is there a NEW.amount?



Kindly help out.




Thanks,

Sunday Olutayo





--
Adrian Klaver
adrian.kla...@gmail.com


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


Re: [GENERAL] trigger and plpgsq help needed

2012-09-26 Thread Chris Ernst
On 09/26/2012 10:42 AM, SUNDAY A. OLUTAYO wrote:
> This IF last_id IS NULL THEN suppose to test if last_id is NULL, that is
> the select query did not found it
> then execute the rest of the red sql but it always fail to insert the
> *NEW.amount *into*amount*, every other things fine.

I believe what you're looking for is "IF NOT FOUND THEN" instead of "IF
last_id IS NULL THEN"

Cheers!

- Chris



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


Re: [GENERAL] trigger and plpgsq help needed

2012-09-26 Thread Rob Richardson
Why not use IF FOUND?

RobR

From: pgsql-general-ow...@postgresql.org 
[mailto:pgsql-general-ow...@postgresql.org] On Behalf Of SUNDAY A. OLUTAYO
Sent: Wednesday, September 26, 2012 12:43 PM
To: pgsql-general@postgresql.org
Subject: [GENERAL] trigger and plpgsq help needed

Dear all,

I have issue with the red portion function below;

This IF last_id IS NULL THEN suppose to test if last_id is NULL, that is the 
select query did not found it
then execute the rest of the red sql but it always fail to insert the 
NEW.amount into amount, every other things fine.

Kindly help out.



[GENERAL] trigger and plpgsq help needed

2012-09-26 Thread SUNDAY A. OLUTAYO
Dear all, 

I have issue with the red portion function below; 

This IF last_id IS NULL THEN suppose to test if last_id is NULL, that is the 
select query did not found it 
then execute the rest of the red sql but it always fail to insert the 
NEW.amount into amount , every other things fine. 

Kindly help out. 



CREATE OR REPLACE FUNCTION invoice_trigger_func() RETURNS trigger AS 
$$ 

DECLARE 
last_id integer; 
current_balance_id integer; 
oldbalance numeric(10,2); 
newbalance numeric(10,2); 

BEGIN 

SELECT lastbal_id INTO last_id FROM patient 
WHERE patient_id = NEW.patient_id; 
IF last_id IS NULL THEN 
INSERT INTO balance (invoice_id, patient_id, amount) 
VALUES (NEW.invoice_id, NEW.patient_id, NEW.amount); 
UPDATE patient SET lastbal_id = (SELECT currval('balance_balance_id_seq')) 
WHERE patient_id = NEW.patient_id; 
ELSE 
SELECT amount INTO oldbalance FROM balance 
WHERE balance_id = last_id; 
INSERT INTO balance (invoice_id, patient_id, amount) 
VALUES (NEW.invoice_id, NEW.patient_id, oldbalance + NEW.amount); 
UPDATE patient SET lastbal_id = (SELECT currval('balance_balance_id_seq')) 
WHERE patient_id = NEW.patient_id; 
END IF; 
RETURN NEW; 

END; 
$$ LANGUAGE plpgsql; 



Thanks, 

Sunday Olutayo