473,320 Members | 1,979 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,320 software developers and data experts.

Updating a unique constrant

I've having trouble with updating a unique index. Briefly:
CREATE TABLE playlist (
[...]
playorder numeric UNIQUE NOT NULL,
[...]
};

CREATE TABLE globals (
[...]
current_play numeric NOT NULL REFERENCES playlist(playorder),
[...]
);

INSERT INTO playlist(playorder) VALUES (1);
INSERT INTO playlist(playorder) VALUES (2);
INSERT INTO playlist(playorder) VALUES (3);
[...]
INSERT INTO playlist(playorder) VALUES (217);

UPDATE playlist SET playorder = playorder + 123 FROM globals WHERE
playorder > current_play;
If current_play is less than 94, I get uniqueness error. Since the update
is most likely to be done when playorder = 1, this is a problem. I
switched to the slower numeric to try doing insert values (1+1/123), but
then I can't do SELECT ... WHERE playorder = 1.00813008130081. (It returns
false.) Is there a way out of my problem without removing the unique index
and the foreign keys that use it?

--
Peter Rahm-Coffey

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #1
4 1575
On Fri, Jun 04, 2004 at 13:09:40 -0600,
Peter Rahm-Coffey <Ra******@radio1190.org> wrote:

If current_play is less than 94, I get uniqueness error. Since the update
is most likely to be done when playorder = 1, this is a problem. I
switched to the slower numeric to try doing insert values (1+1/123), but
then I can't do SELECT ... WHERE playorder = 1.00813008130081. (It returns
false.) Is there a way out of my problem without removing the unique index
and the foreign keys that use it?


Uniqueness constraints can't be deferred. One common strategy is to change
all of the values to values in a set disjoint from what they are now union
with what they will be. (Commonly people make the negative of their
current value.) And then change them to the correct new values.

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #2
On Fri, Jun 04, 2004 at 13:09:40 -0600,
Peter Rahm-Coffey <Ra******@radio1190.org> wrote:

If current_play is less than 94, I get uniqueness error. Since the update
is most likely to be done when playorder = 1, this is a problem. I
switched to the slower numeric to try doing insert values (1+1/123), but
then I can't do SELECT ... WHERE playorder = 1.00813008130081. (It returns
false.) Is there a way out of my problem without removing the unique index
and the foreign keys that use it?


Uniqueness constraints can't be deferred. One common strategy is to change
all of the values to values in a set disjoint from what they are now union
with what they will be. (Commonly people make the negative of their
current value.) And then change them to the correct new values.

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #3
On Sun, 6 Jun 2004, Bruno Wolff III wrote:
Uniqueness constraints can't be deferred. One common strategy is to change
all of the values to values in a set disjoint from what they are now union
with what they will be. (Commonly people make the negative of their
current value.) And then change them to the correct new values.


Thanks for the advice. I already screwed up my test database when tring to
make it work without the unique index.
--
Peter of the Norse
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #4
On Sun, 6 Jun 2004, Bruno Wolff III wrote:
Uniqueness constraints can't be deferred. One common strategy is to change
all of the values to values in a set disjoint from what they are now union
with what they will be. (Commonly people make the negative of their
current value.) And then change them to the correct new values.


Thanks for the advice. I already screwed up my test database when tring to
make it work without the unique index.
--
Peter of the Norse
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #5

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

Similar topics

1
by: Eric Kiernan | last post by:
i have a recordset which is populated by an sql query similar "select customer.custnum,customer lname+customer.fname as name,loans.loannum,loans.writeoffdate from customer,loans where...
1
by: Marius Kaizerman | last post by:
Hi, I'm working with access and sql server. I have two tables. Fields in table #1: barcode (unique),transfer_to,quantity_of_items,supplier,price,date_of_shipment Fields in table #2: barcode...
0
by: Peter Rahm-Coffey | last post by:
I've having trouble with updating a unique index. Briefly: CREATE TABLE playlist ( playorder numeric UNIQUE NOT NULL, }; CREATE TABLE globals (
1
by: Robert Fitzpatrick | last post by:
I am running PostgreSQL 7.4.5 and have a trigger on a table called tblriskassessors which inserts, updates or delete a corresponding record in tblinspectors by lookup of a contact id and license...
3
by: Asaf | last post by:
Hi, I have a MSSQL 2005 test DB with two tables: Table "T1Customers": T1CustomersRowEnum (PK, int, Not Null) T1CustomersFullName (nvarchar(50) null) Table "T2Details":
1
by: Lars E | last post by:
Hi all I have a small problem. I have a datatable with 8 columns. But it is only data in 5 of the columns. Data for the remaing 3 columns is in another dataset. I Want to run trough the...
33
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range...
2
by: UKuser | last post by:
Hi Folks, I havent used javascript in ages, and am not the worlds guru, but I'm playing with ajax linking to my database and an updating area. I have an area named display for example which...
10
by: chimambo | last post by:
Hi All, I have a little problem. I am retrieving records from a table and I want to update the records using checkboxes. I am able to display the database record quite alright and I have created...
5
by: rosaryshop | last post by:
I'm working a jewelry/rosary design web site at http://www.rosaryshop.com/rosariesAndKits2.php. As the user makes selections, it updates images of various parts, giving them a preview of the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.