Re: Re: Re: RANDOM function?

Поиск
Список
Период
Сортировка
От Einar Karttunen
Тема Re: Re: Re: RANDOM function?
Дата
Msg-id Pine.LNX.4.33.0107311621240.20135-100000@melkinpaasi.cs.Helsinki.FI
обсуждение исходный текст
Ответ на Re: Re: Re: RANDOM function?  (Neal Lindsay <neal.lindsay@peaofohio.com>)
Ответы Re: Re: Re: Re: RANDOM function?  (ghaverla@freenet.edmonton.ab.ca)
Список pgsql-novice
On Tue, 31 Jul 2001, Neal Lindsay wrote:

> I think that what you want to do is create a trigger (or rule?) that pulls
> up your random number and then checks to see if it exists already.  I
> haven't used triggers yet, but it should not be too hard.  Also, what
> happens when you declare a column unique, and a function like random()
> tries to give it a non-unique number?
>
This can be accomplished very easily.

CREATE TABLE tbl (
    col integer default (random()*2147483647) unique,
    col2 text
    );

INSERT INTO tbl (col2) VALUES ('the value of col2');

the insert will fail if the number is not unique then just perform it
anew.

- Einar Karttunen


В списке pgsql-novice по дате отправления:

Предыдущее
От: Neal Lindsay
Дата:
Сообщение: Re: Re: Re: RANDOM function?
Следующее
От: ghaverla@freenet.edmonton.ab.ca
Дата:
Сообщение: Re: Re: Re: Re: RANDOM function?