473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 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 2839
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 INSERT. When I tried to issue a COMMIT, right after...
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 no problems expect with 1 table. I get a "the...
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? Otherwise I have to run a select query to see if...
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 statement out of it. Using a response.write...
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 sqldatasource control. I know that while using...
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); but I get ERROR 1093 (HY000): You can't specify...
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. What I'm seeing is this: 1) When performing a...
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 the data fine, and I can easily merge it with...
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 unique ID in each row. 2. I need to insert rows...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.