Re: Web + Slicing/Paging datas

From: durumdara <durumdara(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Web + Slicing/Paging datas
Date: 2009-04-23 09:19:11
Message-ID: 49F0328F.2040206@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi!

2009.04.23. 9:23 keltezéssel, John R Pierce írta:
> durumdara wrote:
>> Hi!
>>
>> In a mod_py application I wanna write a wrapper that handle all PSQL
>> data view with paging/slicing.
>>
>> ..
>> Inserts all records to a temp table.
>> Check the affected rows (as count).
>> Slicing the records.
>> Fetch the slice records.
>> Destroy temp table.
>
>
> how about KEEPING the data in this slice format, and keeping the count
> somewhere ? you'd need to update the count and slice info when new
> data gets added, but perhaps thats better than doing it every time you
> want to view a slice?
>
>
This is a complicated thing.
These datas are provided by a query, with some user's conditions.
For example:
Text = Free String Search
Live = This data is living
Category = Some category
SubCategory = Some subcategory
...
etc.

So your way is possible working with this pseudo code:

def Slicing(PageIndex, Conditions):
# Del recs that have older than 30 minutes
delsql = "delete from pagingtable where inserted < %s" %
IncWithMinutes(Now, -30)
ExecSQL(delsql)
# The Query
datasql = BuildSQL(Conditions)
# Have same query in the pool?
checksql = "select count from pagingtable where sql='%s'" %
SafeEscape(datasql)
records = ExecSQL(checksql)
if records:
# Yes
count = records[0]['COUNT']
else:
# No, we must run a count sql to check
countsql = BuildSQL(Conditions, Count = 1)
datarecords = ExecSQL(countsql)
datarecord = datarecords[0]
count = datarecord['COUNT']
# We must insert it to the paging table
InsertPagingRecord(datasql, count)
...
# Use the count
...
finalsql = BuildSQL(Conditions, WithPaging = PageIndex)
finalrecords = ExecSQL(finalsql)
...

But possible it is too complex and I fear that it cause more pain than I
winning in it... (deadlocks?)...

Thanks for your help:
dd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ivan Sergio Borgonovo 2009-04-23 09:33:34 varchar vs. text + constraint/triggers was: Help request to improve function performance
Previous Message Karsten Hilbert 2009-04-23 09:18:43 Re: Help request to improve function performance