PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 8th, 2003, 09:29 AM
amit26 amit26 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 2 amit26 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Removing Duplicates

I'm applying a sequence to a list of attributes sequentially, and if you have already incremented the sequence (made a primary key) for a attribute and then you come across the same attribute in the list, how do you stop it from incrementing the sequence because I have already created primary key for it.

For example takes the series of insert statements below:

INSERT INTO REC_COMPANY VALUES(company_seq.nextval,'Columbia');
INSERT INTO REC_COMPANY VALUES
(company_seq.nextval,'CBS Records');
INSERT INTO REC_COMPANY VALUES(company_seq.nextval,'RCA');
INSERT INTO REC_COMPANY VALUES(company_seq.nextval,'Virgin records');
INSERT INTO REC_COMPANY VALUES(company_seq.nextval,'BMG');
INSERT INTO REC_COMPANY VALUES(company_seq.nextval,'Polydor');
INSERT INTO REC_COMPANY VALUES(company_seq.nextval,'CBS');
INSERT INTO REC_COMPANY VALUES(company_seq.nextval,'Pickwick');
INSERT INTO REC_COMPANY VALUES(company_seq.nextval,'Polydor');
INSERT INTO REC_COMPANY VALUES(company_seq.nextval,'Atlantic');
INSERT INTO REC_COMPANY VALUES(company_seq.nextval,'Mega');
INSERT INTO REC_COMPANY VALUES(company_seq.nextval,'Grammy');
INSERT INTO REC_COMPANY VALUES(company_seq.nextval,'Musik Master');
INSERT INTO REC_COMPANY VALUES(company_seq.nextval,'Columbia');
INSERT INTO REC_COMPANY VALUES(company_seq.nextval,'Polydor');
INSERT INTO REC_COMPANY VALUES(company_seq.nextval,'WEA');
INSERT INTO REC_COMPANY VALUES(company_seq.nextval,'London');
INSERT INTO REC_COMPANY VALUES
(company_seq.nextval,'EMI');
INSERT INTO REC_COMPANY VALUES(company_seq.nextval,'Columbia');

In this example the record company 'columbia' comes up three times and therefore has three primary keys as i have to increment the sequence counter with every insert statement.

Can i use "if" and "else" to say that if the value exists then don't create a new sequence. How do i do this ?

I need some PL/SQL code to say something like

if the value in column two already exists
then do nothing
else
insert into table
end if


Any ideas on how to right such code? Any help would be much appreciated!

Reply With Quote
  #2  
Old February 10th, 2003, 01:01 PM
ultraslacker's Avatar
ultraslacker ultraslacker is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 56 ultraslacker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
You could use a function for this but why not place a unique index on name?


INSERT rec_company (NAME) values ('EMI') would fail if EMI already exists.
__________________
Casuistry Agnostic

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Removing Duplicates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT