![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, * I have a table pointattributes(pointid,attributeid,strvalue,numva lue)......where pointid and attributeid are foreign keys refering to other tables. Now how can i overwrite tuples in this table. To make it simpler, pointid******* attributeid******* strvalue******* numvalue ---------------------------------------------------------------------- 4******************* 45******************* hello*************** 3 7******************* 50******************* hai*******************9 * I want this table to retain the latest data..... so if i say insert into pointattributes values(7,50,'Good Morning',10), it should overwrite the previous tuple with this latest one.*Is there a way to do that. One simple way is to check if there are any tuples with the given pointid and attributeid, if a tuple exists delete the tuple with the pointid and attribute(the combination is unique) and then insert the new tuple. But is there any better way to do that. * Thanks in advance. * With Best Regards Pradeep Kumar P J |
#3
| |||
| |||
|
|
Hi, * I have a table pointattributes(pointid,attributeid,strvalue,numva lue)......where pointid and attributeid are foreign keys refering to other tables. Now how can i overwrite tuples in this table. To make it simpler, pointid******* attributeid******* strvalue******* numvalue ---------------------------------------------------------------------- 4******************* 45******************* hello*************** 3 7******************* 50******************* hai*******************9 * I want this table to retain the latest data..... so if i say insert into pointattributes values(7,50,'Good Morning',10), it should overwrite the previous tuple with this latest one.*Is there a way to do that. One simple way is to check if there are any tuples with the given pointid and attributeid, if a tuple exists delete the tuple with the pointid and attribute(the combination is unique) and then insert the new tuple. But is there any better way to do that. * Thanks in advance. * With Best Regards Pradeep Kumar P J |
#4
| |||
| |||
|
|
No I am not looking for UPDATE command.For updating first i should check if there is a tuple with the given pointid and attributeid, if present then i should use the UPDATE command.....thats fine. But what I wanted was a situation wherein, I will blindly call the insert command and the database takes care of overwriting the previous values.....is that possible. |
#5
| |||
| |||
|
|
(Unfortunately, you cannot use a transaction, because the failing UPDATE would abort the transaction. However, I believe the nested-transaction feature of PostgreSQL 8 (still in beta) would allow to do such things. Someone please correct me if I'm wrong ...) |
#6
| |||
| |||
|
|
You are correct. However, he can do it right now the other way around, if it can be nested into a plpgsql function or done with libpq: do an UPDATE, check the number of rows affected, and if it's 0, do an insert. By 8.1/8.2 we'll likely have implemented the new SQL spec for this sort of operation, and this common problem will go away. Mind you, it's not a problem I've ever personally had. I'm actually a bit puzzled about how the application could NOT know whether it's handling a new or a modified row; makes me wonder about people's application design. All, |
![]() |
| Thread Tools | |
| Display Modes | |
| |