Hi,
I have a problem when inserting rows into my table tblfactuurpost that
references a table tblfactuur which is a parent to tblclientfactuur.
The actual row is inserted into tblfactuur.
The problem is that i cannot insert the row into tblfactuurpost (which
references the parent table tblfactuur) because PSQL complains the
referencing ID (2) is missing while it is actually *not* missing at all.
Thanks to anyone who can shed some light ...
I have the following table set-up:
CREATE TABLE tblfactuur (id serial PRIMARY KEY,number int NOT NULL,year int NOT NULL CHECK (year>=1900 AND year<=2999),
vanaf date NOT NULL,tot date NOT NULL CHECK (tot > vanaf),
total int -- totaalbedrag in centen
);
CREATE TABLE tblclientfactuur (client int NOT NULL REFERENCES tblclient (id) ON DELETE RESTRICT, PRIMARY KEY (id)
) INHERITS (tblfactuur);
CREATE TABLE tblfactuurpost (id serial PRIMARY KEY,factuur int NOT NULL REFERENCES tblfactuur (id) ON DELETE CASCADE
DEFERRABLE,
omschrijving varchar(128),
btw smallint DEFAULT 19, -- standaard 19% btwaantal decimal(8,1) NOT NULL CHECK (aantal >= 0), -- aantalperstuk int NOT
NULLCHECK (perstuk >= 0), -- bedrag per stuk in
centenamount int NOT NULL CHECK (amount >= 0), -- totaal bedrag in centen
position smallint CHECK (position >= 0)
);
This is the data in tblfactuur:
(db)=> select * from tblfactuur;id | number | year | vanaf | tot | total
----+--------+------+------------+------------+-------- 2 | 1 | 2010 | 2010-03-01 | 2010-04-01 | 397800
(1 row)
I try to insert:
insert into tblfactuurpost (factuur, omschrijving, btw, aantal, perstuk,
amount, position)select ?, ?, ?, ?, ?, ?, count(*) from tblfactuurpost where factuur
= ?;
parameters: (2, Gespecialiseerde 24 uur zorg ma. t/m vr., 19, 156, 1425,
397800, 2)
Regards, David