Re: insert only if conditions are met?

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: insert only if conditions are met?
Дата
Msg-id 1125521444.28179.157.camel@state.g2switchworks.com
обсуждение исходный текст
Ответ на Re: insert only if conditions are met?  ("Jim C. Nasby" <jnasby@pervasive.com>)
Список pgsql-sql
On Wed, 2005-08-31 at 14:54, Jim C. Nasby wrote:
> SELECT sum(hours) FROM table WHERE emp_name = 'JSMITH' AND work_date =
> '8-15-2005'::date will give you the hours. So...
> 
> INSERT INTO table
>     SELECT blah
>     WHERE (SELECT sum(hours) FROM table WHERE emp_name = 'JSMITH' AND work_date =
> '8-15-2005'::date) != 8
> 
> Should do what you want.

I keep thinking a constraint it a better idea here.  Or is this too
complex to make it one easily.

Either way, I'd make that last part:

<8 instead of !=8, in case this uses floating point instead of int, and
gets 8.0000000001 or what not in it.  Or if someone manages to get it up
to 9 or something.


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

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