[BUGS] BUG #5582: check constraints get merged to often with multiple inheritance

2010-07-30 Thread Henk Enting

The following bug has been logged online:

Bug reference:  5582
Logged by:  Henk Enting
Email address:  h.d.ent...@mgrid.net
PostgreSQL version: 9.0beta3, 8.4.4
Operating system:   linux (64 bit)
Description:check constraints get merged to often with multiple
inheritance
Details: 

Check constraints in a multi-level table hierarchy using multiple
inheritance get merged too often. The result is that lower level constraints
have a too-high value of coninhcount and are not removed when the parent
table's constraint is removed. 

The bug was posted yesterday in the postgresql-hackers list but it probably
belongs here. 

The original post (+ a proposed patch):
http://archives.postgresql.org/pgsql-hackers/2010-07/msg01499.php

Regards,

Henk Enting

Test script with comments detailing the problem:

/*

First, create a local inheritance structure:

level_0_parent
level_0_child inherits level_0_parent

This structure is the base level. The table definition and also check
constraints are defined on this level.

Add two levels that inherit this structure:

level_1_parent inherits level_0_parent
level_1_child inherits level_1_parent, level_0_child

level_2_parent inherits level_1_parent
level_2_child inherits level_2_parent, level_1_child

BTW: there is a reason that we want e.g. level_1_child to inherit from
both level_1_parent and level_0_child:
we want the data of level_1_child to be visible in both level_0_child
and level_1_parent

*/
DROP SCHEMA IF EXISTS test_inheritance CASCADE;
CREATE SCHEMA test_inheritance;
SET search_path TO test_inheritance;

CREATE TABLE level_0_parent (i int);
CREATE TABLE level_0_child (a text) INHERITS (level_0_parent);

CREATE TABLE level_1_parent() INHERITS (level_0_parent);
CREATE TABLE level_1_child() INHERITS (level_0_child, level_1_parent);

CREATE TABLE level_2_parent() INHERITS (level_1_parent);
CREATE TABLE level_2_child() INHERITS (level_1_child, level_2_parent);


-- Now add a check constraint on the top level table:
ALTER TABLE level_0_parent ADD CONSTRAINT a_check_constraint CHECK (i IN
(0,1));


/*
Check the "coninhcount" attribute of pg_constraint

Doxygen says this about the parameter:
coninhcount: Number of times inherited from direct parent relation(s)

On our machine (running 9.0beta3) the query below returns a
coninhcount of 3 for the level_2_child table.

This doesn't seem correct because the table only has two direct
parents.
*/


SELECT t.oid, t.relname, c.coninhcount
FROM pg_class t
JOIN pg_constraint c ON (c.conrelid = t.oid)
JOIN pg_namespace n ON (t.relnamespace = n.oid)
WHERE n.nspname = 'test_inheritance'
ORDER BY t.oid;

-- Next, drop the constraint on the top level table

ALTER TABLE level_0_parent DROP CONSTRAINT a_check_constraint;

/*

The constraint should now be dropped from all the tables in the
hierarchy, but the constraint hasn't been dropped on the level_2_child
table. It is still there and has a coninhcount of 1.

*/

SELECT t.oid, t.relname, c.conname, c.coninhcount
FROM pg_class t
JOIN pg_constraint c ON (c.conrelid = t.oid)
JOIN pg_namespace n ON (t.relnamespace = n.oid)
WHERE n.nspname = 'test_inheritance'
ORDER BY t.oid;

/*
Trying to drop this constraint that shouldn't be there anymore won't work.

The "drop constraint" statement below returns:
ERROR:  cannot drop inherited constraint "a_check_constraint" of
relation "level_2_child"

NB after fixing this bug, the statement should return
"constraint does not exist"
*/

ALTER TABLE level_2_child DROP CONSTRAINT a_check_constraint;

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


[BUGS] BUG #6231: weird to_timestamp behaviour with out of range values

2011-09-28 Thread Henk Enting

The following bug has been logged online:

Bug reference:  6231
Logged by:  Henk Enting
Email address:  h.d.ent...@mgrid.net
PostgreSQL version: 9.1.1
Operating system:   linux x86_64
Description:weird to_timestamp behaviour with out of range values
Details: 

I would expect the to_timestamp function to return an error when I feed it
out of range values, e.g. months > 13 and days > 31. Instead it seems to add
the surplus to the timestamp and then return it.

E.g. 21-21 becomes sept. 22th the next year.

psql output:

postgres=# select to_timestamp('2011-21-21', '-MM-DD');
  to_timestamp  

 2012-09-22 00:00:00+02
(1 row)

postgres=# select to_timestamp('2011-21-42', '-MM-DD');
  to_timestamp  

 2012-10-13 00:00:00+02
(1 row)

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


Re: [BUGS] BUG #6231: weird to_timestamp behaviour with out of range values

2011-09-30 Thread Henk Enting
On Thu, Sep 29, 2011 at 5:39 PM, Robert Haas  wrote:

> On Wed, Sep 28, 2011 at 11:43 AM, Tom Lane  wrote:
> > "Henk Enting"  writes:
> >> I would expect the to_timestamp function to return an error when I feed
> it
> >> out of range values, e.g. months > 13 and days > 31. Instead it seems to
> add
> >> the surplus to the timestamp and then return it.
> >
> > What is your reason for using to_timestamp at all?  The timestamp input
> > converter is perfectly capable of dealing with standard formats like
> > -mm-dd, and it does what most people expect in the way of data
> > validation checks.
>
> Well, you might want to insist that the input is in some particular
> format, rather than just "whatever the input function will accept"...
>
Exactly. But I probably can rely on the input function and set the datastyle
parameter to make sure I get the right dates (e.g. in our case 07-04-2011is
in april, not in july).
But still, I think the to_timestamp should throw an error if I put in
something like '21-21-2011'.

Best Regards,

Henk Enting