dbTalk Databases Forums  

Re: [BUGS] constraints & tableoid [pgsql8.1]

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss Re: [BUGS] constraints & tableoid [pgsql8.1] in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Richard Huxton
 
Posts: n/a

Default Re: [BUGS] constraints & tableoid [pgsql8.1] - 04-11-2006 , 03:28 AM






=E7=BB=B4 =E5=A7=9C wrote:
Quote:
jw=3D# CREATE TABLE base ( CHECK (tableoid =3D 'base'::regclass) );
CREATE TABLE
jw=3D# \d base
Table "public.base"
Column | Type | Modifiers
--------+------+-----------
Check constraints:
"base_tableoid_check" CHECK (tableoid =3D 'base'::regclass:id)
=20
jw=3D# INSERT INTO base DEFAULT VALUES ;
ERROR: new row for relation "base" violates check constraint
"base_tableoid_check"
jw=3D#
The CHECK tests the tuple that is being inserted, which doesn't include=20
tableoid. I'm not sure if this counts as a bug or not.

You might be able to do this with a trigger function (although I'm not=20
clear what you're trying to do).

--=20
Richard Huxton
Archonet Ltd


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq


Reply With Quote
  #2  
Old   
Michael Fuhr
 
Posts: n/a

Default Re: [BUGS] constraints & tableoid [pgsql8.1] - 04-11-2006 , 03:44 AM






On Tue, Apr 11, 2006 at 03:11:46PM +0800, ??? ??? wrote:
Quote:
jw=# CREATE TABLE base ( CHECK (tableoid = 'base'::regclass) );
CREATE TABLE
jw=# \d base
Table "public.base"
Column | Type | Modifiers
--------+------+-----------
Check constraints:
"base_tableoid_check" CHECK (tableoid = 'base'::regclass:id)

jw=# INSERT INTO base DEFAULT VALUES ;
ERROR: new row for relation "base" violates check constraint
"base_tableoid_check"
Check the constraint with a function that logs its arguments and
you'll see what's happening:

test=> CREATE FUNCTION toid_check(oid, oid) RETURNS boolean AS $$
test$> BEGIN
test$> RAISE INFO 'toid_check(%, %)', $1, $2;
test$> RETURN $1 = $2;
test$> END;
test$> $$ LANGUAGE plpgsql IMMUTABLE STRICT;
CREATE FUNCTION

test=> CREATE TABLE base (CHECK(toid_check(tableoid, 'base'::regclass)));
CREATE TABLE

test=> INSERT INTO base DEFAULT VALUES;
INFO: toid_check(0, 540339)
ERROR: new row for relation "base" violates check constraint "base_tableoid_check"

Apparently a new row's tableoid isn't set until the row is actually
inserted. Tableoid would be set in an AFTER trigger, but if the
intent is to prevent inheritance then enforcing the constraint with
a trigger on the base table wouldn't work because triggers aren't
inherited.

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend


Reply With Quote
  #3  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] constraints & tableoid [pgsql8.1] - 04-11-2006 , 08:56 AM



Michael Fuhr <mike (AT) fuhr (DOT) org> writes:
Quote:
Apparently a new row's tableoid isn't set until the row is actually
inserted.
I believe that's true of all the system columns. If you're using oid,
for example, that's not assigned either until heap_insert().

This behavior doesn't seem unreasonable to me. A candidate row is not a
member of the table until *after* it's passed its constraint checks ---
until then, it's just some values sitting in memory.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.