dbTalk Databases Forums  

Postgre insert without duplicate

comp.databases.postgresql comp.databases.postgresql


Discuss Postgre insert without duplicate in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #21  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Postgre insert without duplicate - 03-21-2008 , 06:00 AM






Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
You excuse the mine horrible English.
No problem as long as I can grasp what you mean.

Quote:
Example

Table AAA
Field1 A (key unique)
Field2 B

Data
1 10
2 20
3 30

Table BBB
Field1 A (key unique)
Field2 B

Data
3 30 (Primary Key 3 already present in AAA)
4 40
5 00

I should add the data of BBB to AAA without duplications

Executing:

INSERT INTO AAA SELECT * FROM BBB

duplication force Rollback

If an any fact goes in mistake for any motive (Unique Indexes, Foreign
Keys), alone the data in mistake I am to exclude.
Ok, that was clear :^)

How about that:

INSERT INTO aaa
(SELECT * FROM bbb
WHERE NOT EXISTS (SELECT 1 FROM aaa WHERE bbb.a=aaa.a));

which would exclude all duplicates from the SELECT.
I don't think that it can be done more efficiently.

Yours,
Laurenz Albe


Reply With Quote
  #22  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Postgre insert without duplicate - 03-21-2008 , 06:00 AM






Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
You excuse the mine horrible English.
No problem as long as I can grasp what you mean.

Quote:
Example

Table AAA
Field1 A (key unique)
Field2 B

Data
1 10
2 20
3 30

Table BBB
Field1 A (key unique)
Field2 B

Data
3 30 (Primary Key 3 already present in AAA)
4 40
5 00

I should add the data of BBB to AAA without duplications

Executing:

INSERT INTO AAA SELECT * FROM BBB

duplication force Rollback

If an any fact goes in mistake for any motive (Unique Indexes, Foreign
Keys), alone the data in mistake I am to exclude.
Ok, that was clear :^)

How about that:

INSERT INTO aaa
(SELECT * FROM bbb
WHERE NOT EXISTS (SELECT 1 FROM aaa WHERE bbb.a=aaa.a));

which would exclude all duplicates from the SELECT.
I don't think that it can be done more efficiently.

Yours,
Laurenz Albe


Reply With Quote
  #23  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Postgre insert without duplicate - 03-21-2008 , 06:00 AM



Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
You excuse the mine horrible English.
No problem as long as I can grasp what you mean.

Quote:
Example

Table AAA
Field1 A (key unique)
Field2 B

Data
1 10
2 20
3 30

Table BBB
Field1 A (key unique)
Field2 B

Data
3 30 (Primary Key 3 already present in AAA)
4 40
5 00

I should add the data of BBB to AAA without duplications

Executing:

INSERT INTO AAA SELECT * FROM BBB

duplication force Rollback

If an any fact goes in mistake for any motive (Unique Indexes, Foreign
Keys), alone the data in mistake I am to exclude.
Ok, that was clear :^)

How about that:

INSERT INTO aaa
(SELECT * FROM bbb
WHERE NOT EXISTS (SELECT 1 FROM aaa WHERE bbb.a=aaa.a));

which would exclude all duplicates from the SELECT.
I don't think that it can be done more efficiently.

Yours,
Laurenz Albe


Reply With Quote
  #24  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Postgre insert without duplicate - 03-21-2008 , 06:00 AM



Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
You excuse the mine horrible English.
No problem as long as I can grasp what you mean.

Quote:
Example

Table AAA
Field1 A (key unique)
Field2 B

Data
1 10
2 20
3 30

Table BBB
Field1 A (key unique)
Field2 B

Data
3 30 (Primary Key 3 already present in AAA)
4 40
5 00

I should add the data of BBB to AAA without duplications

Executing:

INSERT INTO AAA SELECT * FROM BBB

duplication force Rollback

If an any fact goes in mistake for any motive (Unique Indexes, Foreign
Keys), alone the data in mistake I am to exclude.
Ok, that was clear :^)

How about that:

INSERT INTO aaa
(SELECT * FROM bbb
WHERE NOT EXISTS (SELECT 1 FROM aaa WHERE bbb.a=aaa.a));

which would exclude all duplicates from the SELECT.
I don't think that it can be done more efficiently.

Yours,
Laurenz Albe


Reply With Quote
  #25  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Postgre insert without duplicate - 03-21-2008 , 06:00 AM



Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
You excuse the mine horrible English.
No problem as long as I can grasp what you mean.

Quote:
Example

Table AAA
Field1 A (key unique)
Field2 B

Data
1 10
2 20
3 30

Table BBB
Field1 A (key unique)
Field2 B

Data
3 30 (Primary Key 3 already present in AAA)
4 40
5 00

I should add the data of BBB to AAA without duplications

Executing:

INSERT INTO AAA SELECT * FROM BBB

duplication force Rollback

If an any fact goes in mistake for any motive (Unique Indexes, Foreign
Keys), alone the data in mistake I am to exclude.
Ok, that was clear :^)

How about that:

INSERT INTO aaa
(SELECT * FROM bbb
WHERE NOT EXISTS (SELECT 1 FROM aaa WHERE bbb.a=aaa.a));

which would exclude all duplicates from the SELECT.
I don't think that it can be done more efficiently.

Yours,
Laurenz Albe


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.