Re: insert only if conditions are met?

Поиск
Список
Период
Сортировка
От Ragnar Hafstað
Тема Re: insert only if conditions are met?
Дата
Msg-id 1125520078.2605.38.camel@localhost.localdomain
обсуждение исходный текст
Ответ на Re: insert only if conditions are met?  (Henry Ortega <juandelacruz@gmail.com>)
Ответы Re: insert only if conditions are met?  (Philip Hallstrom <postgresql@philip.pjkh.com>)
Список pgsql-sql
On Wed, 2005-08-31 at 12:49 -0400, Henry Ortega wrote:
> Ok. Here's TABLE A
> 
> emp            date             hours       type
> JSMITH       08-15-2005   5             WORK
> JSMITH       08-15-2005   3             WORK
> JSMITH       08-25-2005   6             WORK
> 
> I want to insert the ff:
> 1.) JSMITH    08-15-2005    8    VAC
> 2.) DOE        08-16-2005    8    VAC
> 
> #1 should fail because there is already 8 hours entered as being
> Worked on 08-15-2005 (same date).

sorry, did not notice the duplicates before my previous reply.

you could do something like
insert into A select 'JSMITH','08-15-2005',8,'VAC'   where       8 != (select sum(hours) FROM A
WHEREemp = 'JSMITH'                    AND date = '8-15-2005');
 

gnari




В списке pgsql-sql по дате отправления:

Предыдущее
От: "Jim C. Nasby"
Дата:
Сообщение: Re: insert only if conditions are met?
Следующее
От: Philip Hallstrom
Дата:
Сообщение: Re: insert only if conditions are met?