Re: Random Numbers/Letters
От | Greg Sabino Mullane |
---|---|
Тема | Re: Random Numbers/Letters |
Дата | |
Msg-id | E16m1Bo-0004vi-00@barry.mail.mindspring.net обсуждение исходный текст |
Ответ на | Random Numbers/Letters ("Hillensbeck, Preston" <PHillensbeck@sfbcic.com>) |
Список | 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 по дате отправления: