Re: SQL Newbie Question

Поиск
Список
Период
Сортировка
От Jim Nasby
Тема Re: SQL Newbie Question
Дата
Msg-id E6B0C7A8-938E-45BE-9254-4786810D1D87@decibel.org
обсуждение исходный текст
Ответ на SQL Newbie Question  (Inoqulath <inoqulath@aol.de>)
Список pgsql-general
On Jan 25, 2007, at 10:30 AM, Inoqulath wrote:
> CREATE TABLE foo(
> id serial,
> a_name text,
> CONSTRAINT un_name UNIQUE (a_name));
>
> Obviously, inserting a string twice results in an error (as one
> would expect). But: is there any known possibility to ingnore an
> errorneous INSERT like SQLite's "conflict
> algorithm" (SQLite:"INSERT OR [IGNORE|ABORT] INTO foo [...]")?
> I tried to use a trigger before INSERT takes place, but it seems
> that before firing a trigger the constraints are checked...
> Background: I'd like to INSERT a few thousand lines in one
> transaction, where some values will be appear twice.

No, though there's a TODO about how to handle MERGE that might
eventually do what you want. In the meantime you'll probably want to
load into a temp table and look for dupes.

Also, I recommend avoiding using 'id' as a field name. It's easy to
get confused when joining a number of tables together when you have
"bare" id's floating all over. Plus, if you use foo_id everywhere you
get to use the USING clause on joins.
--
Jim Nasby                                            jim@nasby.net
EnterpriseDB      http://enterprisedb.com      512.569.9461 (cell)



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

Предыдущее
От: Jim Nasby
Дата:
Сообщение: Re: large document multiple regex
Следующее
От: Jim Nasby
Дата:
Сообщение: Re: Converting 7.x to 8.x