Advertisement

[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

09/01/2006 at 12:46PM PDT, ID: 21975826
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.4

"INSERT ... ON DUPLICATE KEY UPDATE ..." query.

Asked by angelzworld in PostgreSQL Database

Tags: duplicate, update, key, insert

Hi ,

I am trying to write a query in Postgres, for inserting values into a table , however if that INSERT were to insert a row with a duplicate key, it should update the original record in some manner., The duplicate key here is a foreign key so I am not sure how to check it out.

heres the table

*****************************************************
CREATE TABLE colorcode
(
  id int4 NOT NULL,
  tagid int4,
  logicid int4,
  paramvalue float8,
  CONSTRAINT colorcode_pkey PRIMARY KEY (id),
  CONSTRAINT colorcode_logicid_fkey FOREIGN KEY (logicid) REFERENCES logics (id) ON UPDATE RESTRICT ON DELETE RESTRICT,
  CONSTRAINT colorcode_tagid_fkey FOREIGN KEY (tagid) REFERENCES sites (id) ON UPDATE RESTRICT ON DELETE RESTRICT
)
***************************************************

If a row with a similar value of tagid exits, the Insert should update the logicid and the paramvalue for that record with the new values , instead of inserting a complete new record..

I was using something like this...which is giving me an error
"ERROR:  syntax error at or near "ON" at character 138"

*****************************************************
INSERT into colorcode (id,tagid,logicid,paramvalue)
SELECT CAST(nextval as integer),'3', '1','400'    
FROM nextval('colorcode_seq')
ON DUPLICATE Key UPDATE paramvalue = '400'
********************************************************

View the Solution FREE for 30 Days
[+][-]09/02/06 01:00 AM, ID: 17441609

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PostgreSQL Database
Tags: duplicate, update, key, insert
Sign Up Now!
Solution Provided By: earthman2
Participating Experts: 2
Solution Grade: A
 
 
[+][-]09/02/06 03:09 AM, ID: 17441807

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/25/06 01:02 PM, ID: 17595785

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09/30/06 12:58 AM, ID: 17633602

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090429-EE-VQP-58