Re: Random Numbers/Letters - Mailing list pgsql-general

From Greg Sabino Mullane
Subject Re: Random Numbers/Letters
Date
Msg-id E16m1Bo-0004vi-00@barry.mail.mindspring.net
Whole thread Raw
In response to Random Numbers/Letters  ("Hillensbeck, Preston" <PHillensbeck@sfbcic.com>)
List pgsql-general
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


> ... I need to find a way to generate random numbers and letters together
> to insert into a field when a new entry is created....
> If anyone has an easy way for this to be done, please let me know.

The easiest way of all would be to store the image inside the database
itself as a record, eliminating the need for random names entirely. Barring
that, however, your best bet is to have whatever application you are using
generate the random name. You will also have to check for duplicate entries
(perhaps by making the filename column UNIQUE), but collisions should be
very rare for any decent size (say, eight character) string of random
numbers and letters.

No telling what application you are using, but see man(2) mktemp for a
way to do it via a shell command, or do something like this in perl:

my @characters = ('a'..'z','A'..'Z',0..9);
my $ranstring = join('' => @characters[map {rand @characters}(1..8)]);
my $filename = "image_$ranstring.jpg";


Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200203151835

-----BEGIN PGP SIGNATURE-----
Comment: http://www.turnstep.com/pgp.html

iD8DBQE8koVyvJuQZxSWSsgRAuIaAJ0YxmJAOmz6hBTHFon6QSzMq4uDLgCgycJu
Wh4w+7WwFJnUcPc0tCXglBI=
=mJDO
-----END PGP SIGNATURE-----



pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Database quota
Next
From: Sergio Freue
Date:
Subject: Re: Why is it not using an index?