Null values detected as 0 value

Поиск
Список
Период
Сортировка
От Vaduvoiu Tiberiu
Тема Null values detected as 0 value
Дата
Msg-id 980128.74065.qm@web51301.mail.re2.yahoo.com
обсуждение исходный текст
Ответы Re: Null values detected as 0 value  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-novice
Weird stuff is happening to me today...I have a table and a view that has same fields as the table. The table(tb_network) has a field((parent_network_id) which is fk to itself. The view has a rule create for itself:

CREATE OR REPLACE RULE "Network_insert_unconditional" AS
    ON INSERT TO "view_network" DO INSTEAD  INSERT INTO tb_network (...,parent_network_id....)
  VALUES (....new.net_id_parent...)  RETURNING zxt_networks.network_id;

Problem is, when I perform an insert on the view like this:
INSERT INTO view_network (... parent_network_id....)
VALUES (....,NULL,....)

I always get " insert or update on table "tb_network" violates foreign key constraint ..DETAIL: Key (parent_network_id)=(0) is not present in table "tb_network". So even though in the insert query I pass NULL value, in the table, it tries to actually insert 0 instead of null. Has anybody had a similar problem? The constraint is declared like this:

ALTER TABLE tb_network
  ADD CONSTRAINT tb_network_tb_network FOREIGN KEY (parent_network_id)
      REFERENCES tb_network (network_id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED;

Also, if I execute a insert query on the table instead of the view, it works perfectly.


В списке pgsql-novice по дате отправления:

Предыдущее
От: Matthew Walden
Дата:
Сообщение: Re: Help with date query
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Null values detected as 0 value