Re: Unpredicatable behavior of volatile functions used in cursors

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Aleksander Kmetec <aleksander(dot)kmetec(at)intera(dot)si>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Unpredicatable behavior of volatile functions used in cursors
Date: 2007-01-15 15:50:27
Message-ID: 15780.1168876227@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Aleksander Kmetec <aleksander(dot)kmetec(at)intera(dot)si> writes:
> We're using the following technique for counting the number of rows in a cursor:
> DECLARE instance_cur_1 SCROLL CURSOR FOR
> SELECT util.row_number(), *
> FROM (
> $LONG_RUNNING_QUERY
> ) ss
> FETCH LAST IN instance_cur_1;

> util.row_number() is a volatile function written in C which simply returns "++internal_counter" every time it is called.

This isn't gonna work very well if your query involves sorting, because
the SELECT-list is evaluated before the sort step ...

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message thatsanicehatyouhave 2007-01-15 15:57:42 Glacially slow nested SELECT
Previous Message Tom Lane 2007-01-15 15:44:48 Re: Runtime error when calling function from .NET ( Function returns record)