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

Numbering a records

I have this table

content (id int8,owner int8,position int8,timestamp int8,description text,batch int8)

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

I insert to the table following set of rows :

12345, 1000,1,timestamp,blabla,0
12349, 1000,2,timestamp,blabla,0
12355, 1001,1,timestamp,blabla,0
12389, 1000,3,timestamp,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 1877
If you strongly require this data-behavior, you, I think, must create
function afterUpdateOrInsertOrDelete(owner), 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,description text,batch int8)

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

I insert to the table following set of rows :

12345, 1000,1,timestamp,blabla,0
12349, 1000,2,timestamp,blabla,0
12355, 1001,1,timestamp,blabla,0
12389, 1000,3,timestamp,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*******@postgresql.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,description
text,batch int8)

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

I insert to the table following set of rows :

12345, 1000,1,timestamp,blabla,0
12349, 1000,2,timestamp,blabla,0
12355, 1001,1,timestamp,blabla,0
12389, 1000,3,timestamp,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 YourEmailAddressHere" to ma*******@postgresql.org)

Nov 22 '05 #3

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

Similar topics

18
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...
5
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
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...
1
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...
2
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...
1
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...
20
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...
3
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)...
8
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...
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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,...

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.