472,350 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,350 software developers and data experts.

insert duplicated unique/PK with no errors


....what is the best way to force duplicated unique
or primary key'ed row inserts not to raise errors?

duplicated rows can be ignored or updated as well
- it really doesn't matter.

to be specific, i've got:

$ psql -d mydb -c "copy mytable from 'mytable.tsv'

and, with duplicated rows there is an error:

ERROR: copy: line 1, Cannot insert a duplicate key into unique index my_unique

---

ps. i've tried:

CREATE TRIGGER my_trig
BEFORE INSERT OR UPDATE ON mytable FOR EACH
ROW EXECUTE PROCEDURE
check_primary_key('uid', 'mytable', 'uid');

but this function is missing:

ERROR: CreateTrigger: function check_primary_key() does not exist

---

....should i just code my own function?
my guess is that it will be slow
i feel there's better way...

(pgsql v7.x)

/Mirek Rusin
Jul 19 '05 #1
3 2756
Mirek Rusin wrote:
...what is the best way to force duplicated unique
or primary key'ed row inserts not to raise errors?


Doesn't make sense, am I missing the point ?

Regards
Gaetano Mendola
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #2
>>...what is the best way to force duplicated unique
or primary key'ed row inserts not to raise errors?

Remove the columns' UNIQUE or PRIMARY KEY constraints.

Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #3
On Thu, 25 Sep 2003, Gaetano Mendola wrote:
Mirek Rusin wrote:
...what is the best way to force duplicated unique
or primary key'ed row inserts not to raise errors?


Doesn't make sense, am I missing the point ?


I think what he may want is:

create table test (id serial primary key, info text unique);
begin;
insert into test values (DEFAULT,'abc');
INSERT 1
insert into test values (22,'def');
INSERT 1
insert into test values (22,'def');
INSERT 0
commit;

In order to do this, you'll need triggers that fire on the unique / pk
before insertion, and if the values would be dups, to simply drop the
insert silently.

Can that be done, by the way?
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: harborboy76 | last post by:
Hi, I am trying to insert a large number of rows into a table inside a SPL. But every time, I run the SPL, the table is locked because of the...
4
by: bardo | last post by:
Hello all, I have the following problem that I can't seem to solve. I have a database with 6 different tables. when I update the tables I have...
6
by: Tom Allison | last post by:
I seemed to remember being able to do this but I can't find the docs. Can I run a sql query to insert new or update existing rows in one query? ...
9
by: Jack | last post by:
Hi, I am gathering the input values to a form using Request.form method from the processing page. After all the data is captured, I am building sql...
3
by: mahajanvit | last post by:
Hi one and all I got this problem during my project. So in order to solve this I made a very small application. I am trying to insert using SP and...
2
by: Rune Zedeler | last post by:
I need to insert a unique value into a (not auto-increment) column. I try insert into idtest (val) values ((select max(val) from idtest)+1); ...
2
by: Weyus | last post by:
All, Just want to make sure that I understand what's going on here. I have a table with IGNORE_DUP_KEY set on a unique, multi-column index. ...
0
by: mcasey0827 | last post by:
I'm writing a little app to get data from a CSV file generated everyday by a vendor and insert it into a Table in our SQL Server database. I can get...
2
by: aaron1234nz | last post by:
I am trying to insert new rows into a table but there are a few tricky things I have not been able to get my head around. 1. I need to insert a...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.