Bug with views and defaults
Mark Hollomon <mhh@nortelnetworks.com>
From: "Mark Hollomon" <mhh@nortelnetworks.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2000-06-15T14:05:10Z
Lists: pgsql-hackers
CREATE TABLE foo (
name TEXT,
type CHAR(1),
when_added TIMESTAMP DEFAULT 'now'
);
CREATE VIEW mytype AS
SELECT name, when_added FROM foo WHERE type = 'M';
CREATE RULE mytype_insert AS
ON INSERT TO mytype DO INSTEAD
INSERT INTO foo (name, type) VALUES (NEW.name, 'M');
db=# insert into foo (name, type) VALUES ('n1', 'M');
INSERT 414488 1
db=# insert into mytype (name) VALUES ('n2');
INSERT 414489 1
db=# select * from foo;
name | type | when_added
------+------+------------------------
n1 | M | 2000-06-15 09:53:44-04
n2 | M | 2000-06-15 09:52:27-04
(2 rows)
Inserting directly into foo sets when_added to the current time.
Inserting through the view sets it to what looks like the time of
view creation.
--
Mark Hollomon
mhh@nortelnetworks.com
ESN 451-9008 (302)454-9008