Re: Conditional SQL query

Поиск
Список
Период
Сортировка
От Cristóvão B. B. Dalla Costa
Тема Re: Conditional SQL query
Дата
Msg-id 003f01c0477a$04717320$02ffa8c0@terrificus
обсуждение исходный текст
Ответ на Re: Conditional SQL query  (Indraneel Majumdar <indraneel@www.cdfd.org.in>)
Список pgsql-sql
>
> Now I have one more problem. How do I insert only once if value does not
> exist? eg:
>

You should create a unique index on the appropriate fields. For example:

CREATE UNIQUE INDEX indexname ON table (field1, field2)

Then the insert will fail if this particular combination of the values of
(field1, field2) is already in the table.

Be careful if the insert is inside a transaction, tough. If it fails due to
non-uniqueness your transaction will be aborted (all further queries ignored
untill a COMMIT or ROLLBACK).




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

Предыдущее
От: Indraneel Majumdar
Дата:
Сообщение: Re: Conditional SQL query
Следующее
От: Indraneel Majumdar
Дата:
Сообщение: Re: Conditional SQL query