view with insert rule

Started by Philipp Krausover 13 years ago2 messagesgeneral
Jump to latest
#1Philipp Kraus
philipp.kraus@flashpixx.de

Hello,

I use some views for creating some different accessibility of the table data. For inserting I use a rule, which works at the moment, but
my rules runs the SQL statement "insert into myschema.mytable values (new.*)"

If I run on my view the command: insert into myview (field1, field4) values ('first', 123)
it creates an error, because the base table has got some null constraints and other checks. If I create a full insert
statement like "insert into (field1, field2, field3, field4) values (...)" everything works fine.

Can I create a view, that can be used like a table, so on insert statements the default values are set? Can I do
this with trigger ?

Thanks

Phil

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

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Philipp Kraus (#1)
Re: view with insert rule

Philipp Kraus <philipp.kraus@flashpixx.de> writes:

Can I create a view, that can be used like a table, so on insert statements the default values are set?

Sure. Just use ALTER VIEW SET DEFAULT to attach default values to the
columns of the view.

regards, tom lane

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