Re: default value

Lists: pgsql-tr-genel
From: ibrahim saricicek <ibrahimsaricicek(at)gmail(dot)com>
To: pgsql-tr-genel(at)postgresql(dot)org
Subject: default value
Date: 2010-10-22 12:10:01
Message-ID: AANLkTimXqGuNEsxfaSRFZLtVa6BY3ehm7Lra_vyPHGUy@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-tr-genel

Merhaba,

Bir kolona randon RGB color tanımlamak için "trunc(random() * (255-0) +
0)||' '||trunc(random() * (255-0) + 0)||' '||trunc(random() * (255-0) + 0)"
kullanıyorum.
Bunu bir kolonun default değeri yapabilir miyim? Her eklenen satırda random
bir renk kodu oluşmuş olacak böylece?

İyi Çalışmalar...


From: ibrahim saricicek <ibrahimsaricicek(at)gmail(dot)com>
To: pgsql-tr-genel(at)postgresql(dot)org
Subject: Re: default value
Date: 2010-10-22 12:26:48
Message-ID: AANLkTikFieJDgzOxcO=AJmqYs25EdOs6NVfjF9f-pkNv@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-tr-genel

Merhaba,

Pardon çözdüm, teşekkür ederim..
Fonksiyn oluşturup default value olarak tanımladım....

CREATE OR REPLACE FUNCTION get_random_number() RETURNS TEXT AS $$
BEGIN
RETURN trunc(random() * 255)||' '||trunc(random() * 255)||'
'||trunc(random() * 255);
END;
$$ LANGUAGE 'plpgsql' STRICT;

2010/10/22 ibrahim saricicek <ibrahimsaricicek(at)gmail(dot)com>

> Merhaba,
>
> Bir kolona randon RGB color tanımlamak için "trunc(random() * (255-0) +
> 0)||' '||trunc(random() * (255-0) + 0)||' '||trunc(random() * (255-0) + 0)"
> kullanıyorum.
> Bunu bir kolonun default değeri yapabilir miyim? Her eklenen satırda random
> bir renk kodu oluşmuş olacak böylece?
>
> İyi Çalışmalar...
>


From: Devrim GÜNDÜZ <devrim(at)gunduz(dot)org>
To: ibrahim saricicek <ibrahimsaricicek(at)gmail(dot)com>
Cc: pgsql-tr-genel(at)postgresql(dot)org
Subject: Re: default value
Date: 2010-10-22 12:28:17
Message-ID: 1287750497.6569.2.camel@hp-laptop02.gunduz.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-tr-genel

Merhaba,

On Fri, 2010-10-22 at 15:10 +0300, ibrahim saricicek wrote:
> Bir kolona randon RGB color tanımlamak için "trunc(random() * (255-0)
> +
> 0)||' '||trunc(random() * (255-0) + 0)||' '||trunc(random() * (255-0)
> + 0)"
> kullanıyorum.
> Bunu bir kolonun default değeri yapabilir miyim? Her eklenen satırda
> random
> bir renk kodu oluşmuş olacak böylece?

Bu işinize yarar mı?

test=# CREATE TABLE t1 (c1 int, c2 text DEFAULT trunc(random() * (255-0) + 0)||' '||trunc(random() * (255-0) + 0)||' '||trunc(random() * (255-0) + 0));
CREATE TABLE
test=# INSERT INTO t1 VALUES (2,DEFAULT),(3,DEFAULT);
INSERT 0 2
test=# SELECT * from t1;
c1 | c2
----+------------
2 | 41 19 34
3 | 87 249 152
(2 rows)

--
Devrim GÜNDÜZ
PostgreSQL Danışmanı/Consultant, Red Hat Certified Engineer
PostgreSQL RPM Repository: http://yum.pgrpms.org
Community: devrim~PostgreSQL.org, devrim.gunduz~linux.org.tr
http://www.gunduz.org Twitter: http://twitter.com/devrimgunduz