Re: Table partititon hakkında soru

Lists: pgsql-tr-genel
From: Timu <timu(at)cetech(dot)biz>
To: pgsql-tr-genel(at)postgresql(dot)org
Subject: Table partititon hakkında soru
Date: 2007-10-04 15:19:50
Message-ID: 200710041819.53256.timu@cetech.biz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-tr-genel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Merhaba,

Performans açısından bir tabloyu ilişkide bulunduğu bir tabloya göre
partititonlara ayırıyorum, partititonlara ayrılmış olan tablo üzerinde delete
insert, select işlemleri oldukça başarılı ancak şöyle bir durum ile karşı
karşıya kaldım, partition tablolarda bulunan check constraintler'in
kullandığı fieldler üzerinde update işlemi gerçekleştiremiyorum. Bu sorunu
nasıl aşabilirim?

daha iyi anlaşılması açısından aşağıda örnek yapıyı veriyorum.

# \d

public | test | table | root
public | test_1 | table | root
public | test_2 | table | root
public | test_3 | table | root
public | test_id_seq | sequence | root

manager=# \d test
Table "public.test"
Column | Type | Modifiers
- --------+---------+---------------------------------------------------
id | bigint | not null default nextval('test_id_seq'::regclass)
i | integer | not null
Rules:
test_1_rule AS
ON INSERT TO test
WHERE new.i = 1 DO INSTEAD INSERT INTO test_1 (id, i)
VALUES (new.id, new.i)
test_2_rule AS
ON INSERT TO test
WHERE new.i = 2 DO INSTEAD INSERT INTO test_2 (id, i)
VALUES (new.id, new.i)
test_3_rule AS
ON INSERT TO test
WHERE new.i = 3 DO INSTEAD INSERT INTO test_3 (id, i)
VALUES (new.id, new.i)

manager=# \d test_1
Table "public.test_1"
Column | Type | Modifiers
- --------+---------+---------------------------------------------------
id | bigint | not null default nextval('test_id_seq'::regclass)
i | integer | not null
Check constraints:
"test_1_i_check" CHECK (i = 1)
Inherits: test

manager=# \d test_2
Table "public.test_2"
Column | Type | Modifiers
- --------+---------+---------------------------------------------------
id | bigint | not null default nextval('test_id_seq'::regclass)
i | integer | not null
Check constraints:
"test_2_i_check" CHECK (i = 2)
Inherits: test

manager=# update test set i=2 where id=2;
UPDATE 1

manager=# update test set i=1 where id=2;
ERROR: new row for relation "test_2" violates check
constraint "test_2_i_check"

manager=#

- --
Timu EREN <timu(at)cetech(dot)biz>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHBQSZcubzCFA5PLsRAkEzAJ9iDm3yerwXX0VkiZ2tZd+tCXzlFgCgvp/2
9QS1zCro9mfBjQCf4EDHjTA=
=L/GK
-----END PGP SIGNATURE-----


From: Devrim GÜNDÜZ <devrim(at)CommandPrompt(dot)com>
To: Timu <timu(at)cetech(dot)biz>
Cc: pgsql-tr-genel(at)postgresql(dot)org
Subject: Re: Table partititon hakkında soru
Date: 2007-10-04 15:25:07
Message-ID: 1191511507.2667.45.camel@laptop.gunduz.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-tr-genel

Merhaba,

On Thu, 2007-10-04 at 18:19 +0300, Timu wrote:
> partition tablolarda bulunan check constraintler'in kullandığı
> fieldler üzerinde update işlemi gerçekleştiremiyorum

Check constraintler UPDATE RESTRICT ile tanımlanmış olabilir mi?

Bkz:

http://www.gunduz.org/download.php?dlid=25

Kolay gelsin,
--
Devrim GÜNDÜZ
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, ODBCng - http://www.commandprompt.com/


From: Devrim GÜNDÜZ <devrim(at)CommandPrompt(dot)com>
To: Timu <timu(at)cetech(dot)biz>
Cc: "pgsql-tr-genel(at)postgresql(dot)org" <pgsql-tr-genel(at)postgresql(dot)org>
Subject: Re: Table partititon hakkında soru
Date: 2007-10-04 15:54:19
Message-ID: 1191513259.2667.58.camel@laptop.gunduz.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-tr-genel

Merhaba,

Listeyi CC'lerseniz herkes konuyu okuyabilir:

On Thu, 2007-10-04 at 18:54 +0300, Timu wrote:
>
> manager=# update test set i=1 where id=2;
> ERROR: new row for relation "test_2" violates check
> constraint "test_2_i_check"
> manager=#

E bu normal. Daha önceden test tablosunda 2 diye bir kolon var. Sorun da
bu yani:

timu=# DELETE FROM test WHERE id=2;
DELETE 1
timu=# update test set i=1 where id=2;
UPDATE 0

Kolay gelsin,

--
Devrim GÜNDÜZ
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, ODBCng - http://www.commandprompt.com/


From: Timu <timu(at)cetech(dot)biz>
To: Devrim GÜNDÜZ <devrim(at)commandprompt(dot)com>
Subject: Re: Table partititon hakkında soru
Date: 2007-10-04 15:54:24
Message-ID: 200710041854.27442.timu@cetech.biz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-tr-genel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thursday 04 October 2007 18:25:07 you wrote:
> Merhaba,
>
> On Thu, 2007-10-04 at 18:19 +0300, Timu wrote:
> > partition tablolarda bulunan check constraintler'in kullandığı
> > fieldler üzerinde update işlemi gerçekleştiremiyorum
>
> Check constraintler UPDATE RESTRICT ile tanımlanmış olabilir mi?
>
> Bkz:
>
> http://www.gunduz.org/download.php?dlid=25
>
> Kolay gelsin,

Açıkcası her hangi bir durum belirtmedim. Yaptığım işlemleri sıra ile
veriyorum.

create table test(id bigserial not null, i integer not null);

create table test_1 (check(i = 1)) inherits(test);
create table test_2 (check(i = 2)) inherits(test);
create table test_3 (check(i = 3)) inherits(test);

create or replace rule test_1_rule AS ON INTSERT TO test WHERE (i = 1) DO
INSTEAD INSERT INTO test_1 (NEW.id, NEW.i);

create or replace rule test_2_rule AS ON INSERT TO test WHERE (i = 2) DO
INSTEAD INSERT INTO test_2 VALUES (NEW.id, NEW.i);

create or replace rule test_3_rule AS ON INSERT TO test WHERE (i = 3) DO
INSTEAD INSERT INTO test_3 VALUES (NEW.id, NEW.i);

insert into test (i) values (1);
insert into test (i) values (2);
insert into test (i) values (3);

select * from test;
id | i
- ----+---
1 | 1
2 | 2
3 | 3
(3 rows)

anager=# select * from test_1;
id | i
- ----+---
1 | 1
(1 row)

select * from test_2;
id | i
- ----+---
2 | 2

select * from test_3;
id | i
- ----+---
3 | 3

manager=# update test set i=1 where id=2;
ERROR: new row for relation "test_2" violates check
constraint "test_2_i_check"
manager=#

Not: Devrim bey kusura bakmayın shortcut'ların kurbanı oldum..

- --
Timu EREN <timu(at)cetech(dot)biz>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHBQyzcubzCFA5PLsRAqyFAJ9DVU9hCfm1B8cTfvgqacYDvzhG+ACeJbIp
wQdSS8fayJ1PFgJQtFyajHQ=
=sYqq
-----END PGP SIGNATURE-----


From: Timu <timu(at)cetech(dot)biz>
To: "pgsql-tr-genel(at)postgresql(dot)org" <pgsql-tr-genel(at)postgresql(dot)org>
Subject: Re: Table partititon hakkında soru
Date: 2007-10-04 16:12:34
Message-ID: 200710041912.37299.timu@cetech.biz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-tr-genel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thursday 04 October 2007 18:54:19 Devrim GÜNDÜZ wrote:
> Merhaba,
>
> Listeyi CC'lerseniz herkes konuyu okuyabilir:
>
> On Thu, 2007-10-04 at 18:54 +0300, Timu wrote:
> > manager=# update test set i=1 where id=2;
> > ERROR: new row for relation "test_2" violates check
> > constraint "test_2_i_check"
> > manager=#
>
> E bu normal. Daha önceden test tablosunda 2 diye bir kolon var. Sorun da
> bu yani:
>
> timu=# DELETE FROM test WHERE id=2;
> DELETE 1
> timu=# update test set i=1 where id=2;
> UPDATE 0
>
> Kolay gelsin,

Eh anormal bir şey var demek istememiştim zaten, öğrenmek istediğim bu işlemi
nasıl gerçekleştirebileceğim. Bir trigger tanımlayarak (UPDATE öncesi eski
data'yı sil ve yeni datayı INSERT et, UPDATE işlemini bitir) yapmak
istemiyorum.

Not: Kusura bakmayın. Bundan sonra shurtcut kullanmayacağım.

- --
Timu EREN <timu(at)cetech(dot)biz>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHBRD1cubzCFA5PLsRAgHEAJ9GYJRc55Bo7EqFDEMdzmp/CCDn4QCgiwte
Ii7Ryjs1Tg8ABCspjQIzBRw=
=E01Q
-----END PGP SIGNATURE-----