473,804 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Numbering a records

I have this table

content (id int8,owner int8,position int8,timestamp int8,descriptio n text,batch int8)

Table is inserted/deleted frequently, 'id' is almoust random.

I insert to the table following set of rows :

12345, 1000,1,timestam p,blabla,0
12349, 1000,2,timestam p,blabla,0
12355, 1001,1,timestam p,blabla,0
12389, 1000,3,timestam p,blabla,0
etc.. There is a many of these records.

Now I need to od some select like this

select * from content where owner='1000' order by timestamp with some limits, offsets etc. It is OK, no problem.

Other select, like to need select a record of user 1000 WHERE position >5 AND position <150 is OK,

But now, some records are inserted, some deleted, some have the timestamp column updated, so column 'position' is not sequential anymore. I need to create some UPDATE ..... where owner='id of the owner' ORDER by timestamp, that will
recalculate column 'position' to contain actual position inside a timestamp ordered table ? (ie. colum position contain an actual order of records that is owned by 'owner' ordered by timestamp ).Please note that usage of plain LIMIT/OFFSET is not what I need.
in close relation to this, I have another problem. I NEED to assign bath number to records from this example. ie in the table content, where owner='id of the owner' ordered by timestamp, set of first 500 record should have the same 'bath' number '1', set of 2nd 500 records should have its batch number '2' etc...

Is it possible and how it can be done ?
PS: Execuse my bad english.

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 22 '05 #1
2 1908
If you strongly require this data-behavior, you, I think, must create
function afterUpdateOrIn sertOrDelete(ow ner), which locks owner's rows
and recalculate position and batch, if needed.
But, imho, experience says that keeping data similar to your position
(ordinal number _without_ holes) is inefficient because concurency
conflicts on paralel updates.

regards,
pajout

NTPT wrote:
I have this table

content (id int8,owner int8,position int8,timestamp int8,descriptio n text,batch int8)

Table is inserted/deleted frequently, 'id' is almoust random.

I insert to the table following set of rows :

12345, 1000,1,timestam p,blabla,0
12349, 1000,2,timestam p,blabla,0
12355, 1001,1,timestam p,blabla,0
12389, 1000,3,timestam p,blabla,0
etc.. There is a many of these records.

Now I need to od some select like this

select * from content where owner='1000' order by timestamp with some limits, offsets etc. It is OK, no problem.

Other select, like to need select a record of user 1000 WHERE position >5 AND position <150 is OK,

But now, some records are inserted, some deleted, some have the timestamp column updated, so column 'position' is not sequential anymore. I need to create some UPDATE ..... where owner='id of the owner' ORDER by timestamp, that will
recalculate column 'position' to contain actual position inside a timestamp ordered table ? (ie. colum position contain an actual order of records that is owned by 'owner' ordered by timestamp ).Please note that usage of plain LIMIT/OFFSET is not what I need.
in close relation to this, I have another problem. I NEED to assign bath number to records from this example. ie in the table content, where owner='id of the owner' ordered by timestamp, set of first 500 record should have the same 'bath' number '1', set of 2nd 500 records should have its batch number '2' etc...

Is it possible and how it can be done ?
PS: Execuse my bad english.

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 22 '05 #2
On Wednesday 18 February 2004 12:56, NTPT wrote:
I have this table

content (id int8,owner int8,position int8,timestamp int8,descriptio n
text,batch int8)

Table is inserted/deleted frequently, 'id' is almoust random.

I insert to the table following set of rows :

12345, 1000,1,timestam p,blabla,0
12349, 1000,2,timestam p,blabla,0
12355, 1001,1,timestam p,blabla,0
12389, 1000,3,timestam p,blabla,0
etc.. There is a many of these records. But now, some records are inserted, some deleted, some have the timestamp
column updated, so column 'position' is not sequential anymore.


If you really need to update "position" to be sequential the simplest method
is procedural code. That is, loop through the records updating "position"
either from client code or using plpgsql.

PS - there is a "timestamp with time zone" type you might want for column
"timestamp"

PPS - Do you really want position/batch to be int8? You're really going to
have several billion batches?

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 22 '05 #3

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

Similar topics

18
4074
by: Michael Hill | last post by:
I have a series of tables that have primary-key / foreign key relationships where the primary key was being incremented in error by 20 instead of by 1. The default cache value was set to 20. It has since been re-set to 1. I'd like to re-number the primary key and then re-set the sequence then back to the correct number to increment. Anyone have any lessons leaned that I need to watch in doing this?
5
4618
by: Charles McCaffery | last post by:
I have written a database with auto-numbering and now wish to remove alkl of my test data and set the auto-numbering back to one. How do I do this please? Charles McCaffery.
3
2843
by: David B | last post by:
I am creating invoices for an app I am busy with. The transactions for the invoice come from 2 tables which store Sales and Facilities Hire. The current arrangement is that I create a temp table using append queries to get transactions from the 2 tables between selected dates. then draw these into a report grouped by the Sales and Facilities Hire This all works fine. However the customer requires invoices (reports) to have consecutive...
1
1913
by: Wayne Aprato | last post by:
I have a report that shows the results of a query. One of the fields is an autonumber field from the query which shows for instance: 120, 121 , 122 for 3 records. Is there a way to have another field that shows the numbering starting from 1 ie. 1, 2, 3? If the records were sorted so that the first field showed the records in the order: 121, 120, 122 then I would need the second field would show them numbered as 2, 1, 3. I would also need...
2
2313
by: Wayne Aprato | last post by:
I posted this yesterday and it seems like a moderator has thrown it in another thread. This is a totally different question to the one asked in that thread, so I'm posting it again. It is not a simple "numbering records on a report" question. It is more complex than that. I have a report that shows the results of a query. One of the fields is an autonumber field from the query which shows for instance: 120, 121 , 122 for 3 records. ...
1
2021
by: Vladimir Koudela | last post by:
Hi people, I am sure most of you have already solved the Access' stupid problem: there is no simple way of numbring of records shown in a continuous form, needed so often (top-lists, achieved place in a contest...). Could you suggest any solution? Thank you, Vladimir
20
2071
by: Prakash | last post by:
Hi ! I have a field "sub_tran_no" in my form in continuous view. When the user presses a button "Re-Number", I'd like to: 1) Save the current record pointer position 2) Save the current field which has focus 3) go to the top of the recordset & start re-numbering the "sub_tran_no" field with the values 1,2,3, until eof.
3
2605
by: Chris | last post by:
Before I started to create table, etc to track unique form field record number assigments I thought I'd check to see if there is now a better way to do this in .NET. I have a parent form (table) and children form (table). Relationship equals one to many. I'd like to auto number the fields accordingly and traditionaly I assign a unique number based on a table value that I retrieve + 1. i.e. Parent record field value = 1 Children record...
8
2758
by: jcoleshill | last post by:
Hello, I am new to Access, I'm trying to make the switch from Excel to Access as the databases I'm working with have over 200,000 records. In excel, when you want a field to autofill numbering, it's easy. You type in 1,2,3,4 etc. highlight this and drag or double click and magic the rest of the records are filled in for this field with the continued counting. How the $#^%&$%#@ does one do this in Access. I have 2003. Please Help!
4
5949
by: buncey | last post by:
Hi Is there a method of changing the auto numbering sequence whilst retaining the exisiting records along with thier original ID numbers? What I am trying to say is, I have a table with records numbered 100000 to 100999 and I need to change the starting number to 200000 so the next set of records within the same table can be clearly seperated by thier starting number. So, the last record entered will be numbered 100999 and the next new...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10354
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10101
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9177
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6870
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3837
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.