Re: about select use random

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



wangqi <wangqi@xxxxxxxxxxx> writes:
> ¡öSQL-3
> select * from wk_mclid1 where id1= (round((random() * (10-1))::integer)
> + 1)::integer;

> When we excute SQL-3,sometimes the result was 0 record or more than 1
> record.

> Why?

random() is re-evaluated for each row scanned by the SELECT.

If you don't want that, you can use a WITH to lock down the result of a
single random() call.

			regards, tom lane

-- 
Sent via pgsql-admin mailing list (pgsql-admin@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux