Problem with volatile function

Поиск
Список
Период
Сортировка
От Artacus
Тема Problem with volatile function
Дата
Msg-id 4859CE4E.5010501@comcast.net
обсуждение исходный текст
Ответы Re: Problem with volatile function  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Problem with volatile function  (Craig Ringer <craig@postnewspapers.com.au>)
Re: Problem with volatile function  (Klint Gore <kgore4@une.edu.au>)
Список pgsql-general
So my understanding of volatile functions is that volatile functions can
return different results given the same input.

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)

--As does this
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
   AND ts.counter = random(1,100)

-- This generates different numbers
SELECT random(1,100), s.*
FROM usr_students s



В списке pgsql-general по дате отправления:

Предыдущее
От: "Douglas McNaught"
Дата:
Сообщение: Re: HA best pratices with postgreSQL
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Problem with volatile function