From: | Jim Nasby <decibel(at)decibel(dot)org> |
---|---|
To: | Inoqulath <inoqulath(at)aol(dot)de> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: SQL Newbie Question |
Date: | 2007-02-02 03:09:19 |
Message-ID: | E6B0C7A8-938E-45BE-9254-4786810D1D87@decibel.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)
From | Date | Subject | |
---|---|---|---|
Next Message | Jim Nasby | 2007-02-02 03:14:42 | Re: Converting 7.x to 8.x |
Previous Message | Jim Nasby | 2007-02-02 03:06:34 | Re: relationship in a table |