Re: [SQL] Random sort with distinct

2010-10-04 Thread Ozer, Pam
What about dynamic queries? From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Dmitriy Igrishin Sent: Saturday, October 02, 2010 6:40 AM To: Ozer, Pam Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Random sort with distinct Hey Ozer, How about

Re: [SQL] Random sort with distinct

2010-10-02 Thread Tom Lane
"Ozer, Pam" writes: > Select Distinct VehicleMake, VehicleModel > From VehicleYearMakeModelTrim > Order by random() > Limit 10; > I don't want to bring back the random number I just want the sort order > to be random. How can I sort randomly? This query breaks because > random() is not in the se

Re: [SQL] Random sort with distinct

2010-10-02 Thread Lee Hachadoorian
This runs fine on my 8.4 install. What version are you using and what error message are you getting? --Lee On 10/01/2010 04:51 PM, Ozer, Pam wrote: I have the following query   Select Distinct VehicleMake, VehicleModel From VehicleYearMakeModelTrim Order by random()

Re: [SQL] Random sort with distinct

2010-10-02 Thread Dmitriy Igrishin
Hey Ozer, How about dynamic queries? 2010/10/2 Ozer, Pam > I have the following query > > > > Select Distinct VehicleMake, VehicleModel > > From VehicleYearMakeModelTrim > > Order by random() > > Limit 10; > > > > I don’t want to bring back the random number I just want the sort order to > be

[SQL] Random sort with distinct

2010-10-02 Thread Ozer, Pam
I have the following query Select Distinct VehicleMake, VehicleModel >From VehicleYearMakeModelTrim Order by random() Limit 10; I don't want to bring back the random number I just want the sort order to be random. How can I sort randomly? This query breaks because random() is not in the

Re: [SQL] Random Unique Id

2009-10-20 Thread Craig Ringer
Nahuel Alejandro Ramos wrote: > Hi all, > I was searching for a sequence (for serials) that let me use a random > unique number ID on a Primary Key or a simple index. > I have not found a solution so I have done it by myself. I would like to > share it so here it is: Here's what I'm using: ht

Re: [SQL] Random Unique Id

2009-10-20 Thread Ivan Sergio Borgonovo
On Tue, 20 Oct 2009 16:49:17 -0300 Nahuel Alejandro Ramos wrote: > Hi all, > I was searching for a sequence (for serials) that let me use a > random unique number ID on a Primary Key or a simple index. > I have not found a solution so I have done it by myself. I would > like to share it so he

Re: [SQL] Random Unique Id

2009-10-20 Thread Nahuel Alejandro Ramos
:D, Yeah, i know. Its only an example. We are using this algorithm to give a random unique Id to our clients. The need was to give a PK absolute independent of time. Thanks to Ivan, for the pseudo-random posted, I am looking it. Regards... Nahuel Alejandro Ramos. On Tue, Oct 20, 2009 at 5:0

Re: [SQL] Random Unique Id

2009-10-20 Thread Rob Sargent
Suit yourself, of course, but the numbers on my credit cards are far, far from random :) Nahuel Alejandro Ramos wrote: > Yes. I looked this solution but it is not a "only numbers" ID. I would > like a random unique "number" Id. For example: generate a credit number > randomly (like the example I

Re: [SQL] Random Unique Id

2009-10-20 Thread Nahuel Alejandro Ramos
Yes. I looked this solution but it is not a "only numbers" ID. I would like a random unique "number" Id. For example: generate a credit number randomly (like the example I post). I used to insert an MD5 field but this time I need "only numbers" Id. Regards... Nahuel Alejandro Ramos. On Tue

Re: [SQL] Random Unique Id

2009-10-20 Thread Rob Sargent
Nahuel Alejandro Ramos wrote: > Hi all, > I was searching for a sequence (for serials) that let me use a random > unique number ID on a Primary Key or a simple index. > I have not found a solution so I have done it by myself. I would like > to share it so here it is: > > --

[SQL] Random Unique Id

2009-10-20 Thread Nahuel Alejandro Ramos
Hi all, I was searching for a sequence (for serials) that let me use a random unique number ID on a Primary Key or a simple index. I have not found a solution so I have done it by myself. I would like to share it so here it is: -- -- Create language "plpgsql" -- --

Re: [SQL] Random Unique Integer

2007-06-14 Thread Kristo Kaiv
On 14.06.2007, at 22:40, Campbell, Lance wrote: I have a web application that is used to create web surveys and web forms. Users can create any number of surveys or forms at any time. The primary key on one of my tables defines the ID for any given form or survey. I do NOT want the number s

Re: [SQL] Random Unique Integer

2007-06-14 Thread Campbell, Lance
EMAIL PROTECTED] Sent: Thursday, June 14, 2007 8:26 AM To: Campbell, Lance Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Random Unique Integer On Thu, Jun 14, 2007 at 08:08:26AM -0500, Campbell, Lance wrote: > I have a table T1. It contains a field called F1. Is there a way for > me to set

Re: [SQL] Random Unique Integer

2007-06-14 Thread Michael Fuhr
On Thu, Jun 14, 2007 at 08:08:26AM -0500, Campbell, Lance wrote: > I have a table T1. It contains a field called F1. Is there a way for > me to set the table T1 up such that F1 can be populated with a random > integer such that F1 is a unique integer? What problem are you trying to solve? The s

[SQL] Random Unique Integer

2007-06-14 Thread Campbell, Lance
I have a table T1. It contains a field called F1. Is there a way for me to set the table T1 up such that F1 can be populated with a random integer such that F1 is a unique integer? I would rather not create a stored procedure. Thanks, Lance Campbell Project Manager/Software Archit

Re: [SQL] Random()

2006-11-18 Thread Rajesh Kumar Mallah
On 11/18/06, A. Kretschmer <[EMAIL PROTECTED]> wrote: am Sat, dem 18.11.2006, um 23:02:33 +0530 mailte Rajesh Kumar Mallah folgendes: > >select from order by random() limit 1; > > This query will tend to get slower as the table grows because of the > sorting. Right. > > it possible to get

Re: [SQL] Random()

2006-11-18 Thread A. Kretschmer
am Sat, dem 18.11.2006, um 23:02:33 +0530 mailte Rajesh Kumar Mallah folgendes: > >select from order by random() limit 1; > > This query will tend to get slower as the table grows because of the > sorting. Right. > > it possible to get a row from a random offset > how about > > select fr

Re: [SQL] Random()

2006-11-18 Thread Rajesh Kumar Mallah
On 11/17/06, A. Kretschmer <[EMAIL PROTECTED]> wrote: am Thu, dem 16.11.2006, um 16:31:14 -0200 mailte Ezequias Rodrigues da Rocha folgendes: > Hi list, > > I have a bigint collumn and I would like to generate a random number within the > numbers of my column. select from order by random()

Re: [SQL] Random()

2006-11-17 Thread Aaron Bono
On 11/16/06, A. Kretschmer <[EMAIL PROTECTED]> wrote: am Thu, dem 16.11.2006, um 16:31:14 -0200 mailte Ezequias Rodrigues da Rocha folgendes: > Hi list, > > I have a bigint collumn and I would like to generate a random number within the > numbers of my column. select from order by random() l

Re: [SQL] Random()

2006-11-16 Thread Andrew Sullivan
On Thu, Nov 16, 2006 at 06:54:42PM -0200, Ezequias Rodrigues da Rocha wrote: > My bigint field has 20,000 numbers and I'd like to make real random (used > like lottery). If you want _real_ random, you have to use a non-computer source for your randomness. The best you get on a computer is pseudo-

Re: [SQL] Random()

2006-11-16 Thread Ezequias Rodrigues da Rocha
Just another question. I can trust on this random number ? The rule to it is quite tested ? I am thinking in implementing a function that return allways a random number. What do you think of the trust of this function (random()) ? My bigint field has 20,000 numbers and I'd like to make real rand

Re: [SQL] Random()

2006-11-16 Thread Ezequias Rodrigues da Rocha
Thank you so much andreas. Regards http://ezequiasrocha.blogspot.com 2006/11/16, A. Kretschmer <[EMAIL PROTECTED]>: am Thu, dem 16.11.2006, um 16:31:14 -0200 mailte Ezequias Rodrigues da Rocha folgendes: > Hi list, > > I have a bigint collumn and I would like to generate a random number withi

Re: [SQL] Random()

2006-11-16 Thread A. Kretschmer
am Thu, dem 16.11.2006, um 16:31:14 -0200 mailte Ezequias Rodrigues da Rocha folgendes: > Hi list, > > I have a bigint collumn and I would like to generate a random number within > the > numbers of my column. select from order by random() limit 1; Andreas -- Andreas Kretschmer Kontakt: H

[SQL] Random()

2006-11-16 Thread Ezequias Rodrigues da Rocha
Hi list, I have a bigint collumn and I would like to generate a random number within the numbers of my column. Is it possible ? =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Atenciosamente (Sincerely) Ezequias Rodr

Re: [SQL] Random resultset retrieving -> performance bottleneck

2002-08-03 Thread Christopher Kings-Lynne
> I'm running into a performance problem when considering the following > scenario: I have a fairly large table (1mio rows) related to other smaller > tables (between 100 and 1 rows) and would like to retrieve the joined > data (through a view) in random order. In order to do so, the main tabl

Re: [SQL] Random resultset retrieving -> performance bottleneck

2002-08-02 Thread Stephan Szabo
On Thu, 1 Aug 2002, [iso-8859-1] Cédric Dufour wrote: > * > * 2. > * > BEGIN; > SET CONSTRAINTS ALL DEFERRED; > CREATE TEMP TABLE tmp_Large AS SELECT * FROM tb_Table; > DELETE FROM tb_Large; -- won't work; RI violation on foreign key > 'tb_Foo(FK_Large)' > INSERT INTO tb_Large SELECT * F

[SQL] Random resultset retrieving -> performance bottleneck

2002-08-02 Thread Cédric Dufour
Hello to all of you, I'm running into a performance problem when considering the following scenario: I have a fairly large table (1mio rows) related to other smaller tables (between 100 and 1 rows) and would like to retrieve the joined data (through a view) in random order. In order to do so,

Re: [SQL] random rows

2001-04-26 Thread Josh Berkus
Jie, > How I can return random N rows from my select stmt? > like: > e.g. what my selectee is a set of 1000 rows, I want randomly > pickup 100 of 1000. You'd have to do it inside a function or external program, and copy the rows to a temporary table (which is what you'd return to the user). Th

Re: [SQL] random rows

2001-04-26 Thread Joao Pedro M. F. Monoo
Hi! > How I can return random N rows from my select stmt? > like: > e.g. what my selectee is a set of 1000 rows, I want randomly > pickup 100 of 1000. use the LIMIT clause example SELECT * FROM test_table LIMIT 100; you can also use the OFFSET clause to skip to n row and the fetch the n desi

[SQL] random rows

2001-04-26 Thread Jie Liang
How I can return random N rows from my select stmt? like: e.g. what my selectee is a set of 1000 rows, I want randomly pickup 100 of 1000. thanks. Jie LIANG St. Bernard Software 10350 Science Center Drive Suite 100, San Diego, CA 92121 Office:(858)320-4873 [EMAIL PROTECTED] www.stbernard.

Re: [SQL] random

2001-03-07 Thread Tomek Zielonka
On Wed, Mar 07, 2001 at 12:50:36PM +0100, Tomek Zielonka wrote: > On Mon, Mar 05, 2001 at 02:12:15PM -0500, Jelle Ouwerkerk wrote: > > Hi > > > > What would be the best way to select a random row from a result set? > > > > Here's my approach. It allows to get random row from the table, not from

Re: [SQL] random

2001-03-07 Thread Tomek Zielonka
On Mon, Mar 05, 2001 at 02:12:15PM -0500, Jelle Ouwerkerk wrote: > Hi > > What would be the best way to select a random row from a result set? > > Possibilities: > > 1) o get the total number of rows using count() >o generate a random number between 1 and the total >o select the n'th ro

Re: [SQL] random

2001-03-05 Thread Bruce Momjian
> Bruce Momjian <[EMAIL PROTECTED]> writes: > > But random returns a random value from 0-1, right? How does that work > > in ORDER BY? > > What's the problem? Each row gets a different random value, then we > sort. Oh, I see. Nifty. I am used to seeing a column name or number in ORDER BY. W

Re: [SQL] random

2001-03-05 Thread Tom Lane
Bruce Momjian <[EMAIL PROTECTED]> writes: > But random returns a random value from 0-1, right? How does that work > in ORDER BY? What's the problem? Each row gets a different random value, then we sort. regards, tom lane ---(end of broadcast)---

Re: [SQL] random

2001-03-05 Thread Bruce Momjian
> Bruce Momjian <[EMAIL PROTECTED]> writes: > >> Jelle Ouwerkerk <[EMAIL PROTECTED]> writes: > > Also, is there a way to randomize the order of a result set? > >> > >> There's always > >> SELECT * FROM foo ORDER BY random(); > > > However: > > test=> select * from pg_class order by random();

Re: [SQL] random

2001-03-05 Thread Stephan Szabo
On Mon, 5 Mar 2001, Bruce Momjian wrote: > > Jelle Ouwerkerk <[EMAIL PROTECTED]> writes: > > > Also, is there a way to randomize the order of a result set? > > > > There's always > > SELECT * FROM foo ORDER BY random(); > > > > How does that work? > > test=> select random(); >

Re: [SQL] random

2001-03-05 Thread Tom Lane
Bruce Momjian <[EMAIL PROTECTED]> writes: >> Jelle Ouwerkerk <[EMAIL PROTECTED]> writes: > Also, is there a way to randomize the order of a result set? >> >> There's always >> SELECT * FROM foo ORDER BY random(); > However: > test=> select * from pg_class order by random(); > does return s

Re: [SQL] random

2001-03-05 Thread Bruce Momjian
> Jelle Ouwerkerk <[EMAIL PROTECTED]> writes: > > Also, is there a way to randomize the order of a result set? > > There's always > SELECT * FROM foo ORDER BY random(); > How does that work? test=> select random(); random ---

Re: [SQL] random

2001-03-05 Thread Tom Lane
Jelle Ouwerkerk <[EMAIL PROTECTED]> writes: > Also, is there a way to randomize the order of a result set? There's always SELECT * FROM foo ORDER BY random(); regards, tom lane ---(end of broadcast)--- TIP 3: if pos

[SQL] random

2001-03-05 Thread Jelle Ouwerkerk
Hi What would be the best way to select a random row from a result set? Possibilities: 1) o get the total number of rows using count() o generate a random number between 1 and the total o select the n'th row using OFFSET 2) o get the total number of rows using count() o generate a ran