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

[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 sort with distinct

2010-10-02 Thread Dmitriy Igrishin
Hey Ozer, How about dynamic queries? 2010/10/2 Ozer, Pam po...@automotive.com 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

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 Tom Lane
Ozer, Pam po...@automotive.com 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

[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 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: --

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, Oct

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 post).

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

Re: [SQL] Random Unique Id

2009-10-20 Thread Ivan Sergio Borgonovo
On Tue, 20 Oct 2009 16:49:17 -0300 Nahuel Alejandro Ramos nahue...@gmail.com 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

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:

[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

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

Re: [SQL] Random Unique Integer

2007-06-14 Thread Campbell, Lance
] 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 the table T1 up

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

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 bigint_column from your_table 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

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 bigint_column from your_table order by random() limit 1; This query will tend to get slower as the table grows because of the sorting. Right. it

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 bigint_column from your_table

[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

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 bigint_column from your_table order by random() limit 1; Andreas -- Andreas

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 within

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

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 table

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 * FROM

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 desired

[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]

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

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
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 some output. Is

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(); random

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(); does return some

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

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. Why