Skip site navigation (1) Skip section navigation (2)

Re: Access to current database from C-language function

From: David Fetter <david(at)fetter(dot)org>
To: Achim Domma <domma(at)procoders(dot)net>
Cc: Florian Pflug <fgp(at)phlo(dot)org>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Access to current database from C-language function
Date: 2011-08-01 15:04:58
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
On Mon, Aug 01, 2011 at 01:23:26PM +0200, Achim Domma wrote:
> Am 26.07.2011 um 00:40 schrieb Florian Pflug:
> > On Jul25, 2011, at 22:31 , Achim Domma wrote:
> >> Am 25.07.2011 um 14:48 schrieb Florian Pflug:
> >>> A more low-level API is provided by
> >>> {heap,index}_{beginscan,endscan}, heap_{insert,update,delete}
> >>> and index_insert. However, correct handling of transactions
> >>> using this API isn't easy - for example, to update a row you'd
> >>> first have to find the latest version of that row, then decide
> >>> if you're allowed to update it, and finally create a new
> >>> version.
> >> 
> >> I see the problems with the second approach, but that's
> >> definitively what I would like to do.
> > 
> > You're in for a lot of work, then. I still suggest that you
> > explain your ultimate goals before you embark on your endeavor -
> > people might be able to point our easier ways to achieve those.
> I have tables which store two integer IDs and a floating point rank.
> So the table MyTable might have these columns:
> EntityID -> int PropertyID -> int Rank -> float
> My algorithm needs to retrieve EntityID-Rank-Pairs for some given
> PropertyIDs. So I basically want to execute a "select EntityID, Rank
> from MyTable where PropertyID=123 oder by Rank desc". But I need to
> execute multiple of those statements and I don't want to load all
> the data into memory, but rather iterate over the results step by
> step, stopping at certain thresholds.
> My algorithm is somewhat nested and contains logic which I cannot
> express in SQL,

SQL is Turing-complete, so the chances are excellent that it's
possible to express that algorithm in it. ;)

Look into common table expressions for iteration/recursion, and
windowing functions, commonly used for time series.

David Fetter <david(at)fetter(dot)org>
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david(dot)fetter(at)gmail(dot)com
iCal: webcal://

Remember to vote!
Consider donating to Postgres:

In response to


pgsql-hackers by date

Next:From: Robert HaasDate: 2011-08-01 15:18:36
Subject: Re: Access to current database from C-language function
Previous:From: Heikki LinnakangasDate: 2011-08-01 14:34:47
Subject: Re: Hot standby and GiST page splits (was Re: WIP: Fast GiST index build)

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group