Re: Problem with volatile function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Artacus <artacus(at)comcast(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Problem with volatile function
Date: 2008-06-19 03:43:20
Message-ID: 25613.1213847000@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Artacus <artacus(at)comcast(dot)net> writes:
> I have a function random(int, int) that returns a random value between
> $1 and $2. I want to use it in a query to generate values. But it only
> evaluates once per query and not once per row like I need it to.

> -- This always returns the same value
> SELECT ts.sis_id, bldg_id, f_name.name, l_name.name
> FROM tmp_students ts
> JOIN names AS f_name ON
> ts.gender = f_name.gender
> WHERE f_name.counter = random(1,300)

You haven't really explained what your problem is, but offhand I'd
expect random() to be evaluated once per f_name row here. What are
you looking for?

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2008-06-19 04:04:38 Re: Problem with volatile function
Previous Message Artacus 2008-06-19 03:11:10 Problem with volatile function