Handling NULL records in plpgsql

From: Decibel! <decibel(at)decibel(dot)org>
To: Postgres Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Handling NULL records in plpgsql
Date: 2008-10-24 22:29:41
Message-ID: 9CB1F2C2-5B47-4FEE-AE2C-CB55C279C74F@decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Was anything ever done with http://archives.postgresql.org/pgsql-
hackers/2008-09/msg01758.php ?

I have a different issue I'm seeing, but I think it's related, and
ISTM it's a bug (on 8.2.10):

SELECT INTO v_prev *
FROM installments_static
WHERE id = ( SELECT id FROM installments_static i
WHERE i.loan_id = NEW.loan_id AND i.installment_number <
NEW.installment_number
ORDER BY installment_number DESC
LIMIT 1
)
;
...
RAISE DEBUG $$Previous installment: id = %, due_date = %
Current installment: id = %, number = %, loan_id = %,
installment_date = %, due_date = %
Next installment: id = %, installment_date = %
v_prev IS NOT NULL = %, v_prev IS NULL = %
v_next IS NOT NULL = %, v_next IS NULL = %$$
, v_prev.id, v_prev.due_date
, NEW.id, NEW.installment_number, NEW.loan_id,
NEW.installment_date, NEW.due_date
, v_next.id, v_next.installment_date
, v_prev IS NOT NULL, v_prev IS NULL
, v_next IS NOT NULL, v_next IS NULL
;
psql:sql/installments_static.sql:XX: DEBUG: Previous installment: id
= 5, due_date = XXXX-XX-XX
Current installment: id = 8, number = 2, loan_id = 3,
installment_date = XXXX-XX-XX, due_date = XXXX-XX-XX
Next installment: id = <NULL>, installment_date = <NULL>
v_prev IS NOT NULL = f, v_prev IS NULL = f -- v_prev is actually set!
v_next IS NOT NULL = f, v_next IS NULL = t -- v_next is unset, ie:
NULL

If I change v_* IS NOT NULL to NOT v_* IS NULL everything's ok:

psql:sql/installments_static.sql:XX: DEBUG: Previous installment: id
= 5, due_date = XXXX-XX-XX
Current installment: id = 8, number = 2, loan_id = 3,
installment_date = XXXX-XX-XX, due_date = XXXX-XX-XX
Next installment: id = <NULL>, installment_date = <NULL>
NOT v_prev IS NULL = t, v_prev IS NULL = f
NOT v_next IS NULL = f, v_next IS NULL = t
--
Decibel!, aka Jim C. Nasby, Database Architect decibel(at)decibel(dot)org
Give your computer some brain candy! www.distributed.net Team #1828

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2008-10-25 00:07:54 Re: WIP : change tablespace for a database
Previous Message Guillaume Lelarge 2008-10-24 22:02:25 Re: WIP : change tablespace for a database