Re: constraint function, newbie

From: Lee Harr <missive(at)frontiernet(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: constraint function, newbie
Date: 2003-03-22 03:54:11
Message-ID: b5gmp1$1s2o$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In article <pan(dot)2003(dot)03(dot)21(dot)11(dot)28(dot)22(dot)20813(at)druid(dot)if(dot)uj(dot)edu(dot)pl>, Michal Adamczak:
> 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
>

Is there data in the table?

Maybe try it on an empty copy of the database.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-03-22 05:07:13 Re: 32/64-bit transaction IDs?
Previous Message Daniel R. Anderson 2003-03-22 02:49:03 Re: configuration according to the database