Search Postgresql Archives

Re: SQL Newbie Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx
EnterpriseDB      http://enterprisedb.com      512.569.9461 (cell)




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux