Alban Hertroys wrote:
> To follow up on my own post, I came up with a workable solution based on
> scrolling cursors. The SP approach didn't work out for me, I didn't
> manage to declare a cursor in PL/pgSQL that could be positioned
> absolutely (maybe that's due to us still using PG 8.1.something?
To follow up on my own post, I came up with a workable solution based on
scrolling cursors. The SP approach didn't work out for me, I didn't
manage to declare a cursor in PL/pgSQL that could be positioned
absolutely (maybe that's due to us still using PG 8.1.something?).
A solution to that would b
On Sep 1, 2007, at 14:44, Martijn van Oosterhout wrote:
On Sat, Sep 01, 2007 at 02:24:25PM +0200, Alban Hertroys wrote:
Oh, now I see... The first time guarantees that v has a value (as
random() < 1/1), and after that there is a decreasing chance that a
new row gets re-assigned to v. That means
On Sat, Sep 01, 2007 at 02:24:25PM +0200, Alban Hertroys wrote:
> Oh, now I see... The first time guarantees that v has a value (as
> random() < 1/1), and after that there is a decreasing chance that a
> new row gets re-assigned to v. That means the last row has a chance
> of 1/n, which would
On Sep 1, 2007, at 12:44, Alban Hertroys wrote:
It would be possible to write an aggregate that returns a single
random
value from a set. The algorithm is something like:
n = 1
v = null
for each row
if random() < 1/n:
v = value of row
n = n + 1
return v
Doesn't this always return
On Aug 31, 2007, at 15:54, Martijn van Oosterhout wrote:
On Fri, Aug 31, 2007 at 02:42:18PM +0200, Alban Hertroys wrote:
Examples:
* random(maxrows) would return random rows from the resultset.
* median() would return the rows in the middle of the result set
(this
would require ordering to b
On Aug 31, 2007, at 8:34 AM, Kaloyan Iliev wrote:
Alban Hertroys wrote:
Hello,
I've recently been busy improving a query that yields a fixed
number of
random records matching certain conditions. I have tried all the
usual
approaches, and although they do work, they're all limited in some
Hi,
Why not generate a random number in your application and then:
SELECT *
FROM table_x
WHERE condition = true
OFFSET generated_random_number
LIMIT xx
Kaloyan Iliev
Alban Hertroys wrote:
Hello,
I've recently been busy improving a query that yields a fixed number of
random records matching c
On Fri, Aug 31, 2007 at 02:42:18PM +0200, Alban Hertroys wrote:
> Examples:
> * random(maxrows) would return random rows from the resultset.
> * median() would return the rows in the middle of the result set (this
> would require ordering to be meaningful).
It would be possible to write an aggrega
> Dear Santa,
>
> I'd like my database to have functionality analogue to how LIMIT works,
> but for other - non-sequential - algorithms.
There was some discussion before to possibly reuse the algorithm ANALYZE
is using for sampling some given percentage of the table data and
provide this for some
Alban Hertroys wrote:
> I've recently been busy improving a query that yields a fixed
> number of random records matching certain conditions.
> Dear Santa,
>
> I'd like my database to have functionality analogue to how
> LIMIT works,
> but for other - non-sequential - algorithms.
>
> I was thin
On 8/31/07, Alban Hertroys <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I've recently been busy improving a query that yields a fixed number of
> random records matching certain conditions. I have tried all the usual
> approaches, and although they do work, they're all limited in some way
> and don't tr
Hello,
I've recently been busy improving a query that yields a fixed number of
random records matching certain conditions. I have tried all the usual
approaches, and although they do work, they're all limited in some way
and don't translate really well to what you "want". They're kludges, IMHO.
T
13 matches
Mail list logo