constraint function, newbie

From: "Michal Adamczak" <pokryfka(at)druid(dot)if(dot)uj(dot)edu(dot)pl>
To: pgsql-general(at)postgresql(dot)org
Subject: constraint function, newbie
Date: 2003-03-21 11:28:24
Message-ID: pan.2003.03.21.11.28.22.20813@druid.if.uj.edu.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hi
i am learning postgres and made a library model

i dont want a user to be able to borrow 2 items (copies)
of the same book so made a function to check it (below)

the function works fine but now i would like to add a constraint,
unfortunatelly i fail

here's my try:

create function bookborrow_check_insert
(bookborrow.userid%TYPE, bookborrow.bookitem_id%TYPE)
returns bool as
'select NOT $1 in (select userid from bookborrow where userid = $1 and
bookitem_id = $2 and returned is null)'
language sql;

=> alter table bookborrow add check(bookborrow_check_insert (userid, bookitem_id));
ERROR: AlterTableAddConstraint: rejected due to CHECK constraint <unnamed>

=> alter table bookborrow add constraint check_insert check(bookborrow_check_insert (userid, bookitem_id));
ERROR: AlterTableAddConstraint: rejected due to CHECK constraint check_insert

--
Michal Adamczak
pokryfka @ druid.if.uj.edu.pl
GS dpu C+++ UL+++++ L+++(++++) w--- !tv h*
I code AND I bathe. (seen on slashdot)

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Deepa K 2003-03-21 11:45:40 Inserting a bitarray value through storedprocedure
Previous Message Joshua Moore-Oliva 2003-03-21 10:18:16 Re: rules problem