Re: Unpredicatable behavior of volatile functions used in cursors - Mailing list pgsql-general

From Tom Lane
Subject Re: Unpredicatable behavior of volatile functions used in cursors
Date
Msg-id 15780.1168876227@sss.pgh.pa.us
Whole thread Raw
In response to Unpredicatable behavior of volatile functions used in cursors  (Aleksander Kmetec <aleksander.kmetec@intera.si>)
Responses Re: Unpredicatable behavior of volatile functions used  (Aleksander Kmetec <aleksander.kmetec@intera.si>)
List pgsql-general
Aleksander Kmetec <aleksander.kmetec@intera.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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Runtime error when calling function from .NET ( Function returns record)
Next
From: thatsanicehatyouhave@mac.com
Date:
Subject: Glacially slow nested SELECT