Re: Secret Santa List

Поиск
Список
Период
Сортировка
От Lou Duchez
Тема Re: Secret Santa List
Дата
Msg-id 567A6A32.30407@paprikash.com
обсуждение исходный текст
Ответ на Re: Secret Santa List  (Alberto Cabello Sánchez <alberto@unex.es>)
Ответы Re: Secret Santa List  (Alberto Cabello Sánchez <alberto@unex.es>)
Список pgsql-general
> Of course: you can't UPDATE a field with a query returning more than one
> result, as you can check easily trying:

I understand that, and my query does not return more than one result.  The problem is that it returns THE SAME result
eachtime, most likely because the subquery is evaluated exactly once and then the main query uses that single result
overand over. 

update secretsanta set recipient =
( select giver from secretsanta s2 where not exists (select * from
secretsanta s3 where s3.recipient = s2.giver) order by random() limit 1 );

My hope is to somehow persuade PostgreSQL to re-evaluate the subquery each time, and see that the set of available
recipientshas changed.  If "Steve" was picked for the first row, "Steve" shouldn't be available for any subsequent row.
If "Fred" was picked for the second row, neither "Steve" nor "Fred" should be available for any subsequent row. 

> You could get a list of givers in no particular order (e. g. "select giver
> from secretsanta order by md5(concat(giver,current_time))") then setting
> each employee as next's employee giver.

As in, write a loop in some programming language to update the table one row at a time, or did you envision a way to do
thiswith an SQL statement?  I can certainly write a loop, if that's the only solution. 

Thanks!



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

Предыдущее
От: Andreas Kretschmer
Дата:
Сообщение: Re: Transfer db from one port to another
Следующее
От: Killian Driscoll
Дата:
Сообщение: Re: Transfer db from one port to another