Re: referential integrity violation - Mailing list pgsql-general
From | Nigel J. Andrews |
---|---|
Subject | Re: referential integrity violation |
Date | |
Msg-id | Pine.LNX.4.21.0210211547390.3016-100000@ponder.fairway2k.co.uk Whole thread Raw |
In response to | Re: referential integrity violation (mk@fashaf.co.za) |
List | pgsql-general |
On Mon, 21 Oct 2002 mk@fashaf.co.za wrote: > I have tried '' , undef , 'NULL' , 'null' non of them seem to work? > > any idea how to submit a NULL value with perl? > Okay, let's take a step back to view the slightly larger picture rather than the little detail... With a design such as: create table t1 ( i int primary key ); create table t2 ( i int primary key, t text, a int references t1 (a) ); your perl code should be submitting a string such as, note the lack of quotes around the null: insert into mytable values ( 23, 'my text', NULL ) i.e. use Pg; # connect to server etc. $conn->exec("insert into mytable values ( 23, 'my text', NULL )"); # error check etc. Hope this helps. > > > On Fri, 18 Oct 2002 at 10:34:31 -0400, Darren Ferguson wrote: > > > > What is happening is that you are trying to insert and id for slip > > > > printer into the TABLE pc but the id does not exist in the slip printer > > > > table. > > > > > > > > Since you have slip_printer in pc table and you specified that it > > > > references the slip_printer table id then you must have an id in slip > > > > printer for it to insert into the pc table unless you insert a null value > > > > since you did not specify the constraint on the table > > > > > > > > HTH > > > > > > > > On Fri, 18 Oct 2002 mk@fashaf.co.za wrote: > > > > > > > > > Hi guys > > > > > > > > > > I have created a Pg DB, Ive included 2 of the tables. > > > > > When inserting non NULL values everything works just fine, > > > > > but when i want to leave a table empty i get the following error: > > > > > > > > > > EXEC: ERROR: referential integrity violation - key referenced from pc not found in slip_printer > > > > > > > > > > Im recieving the information from a Perl CGI form that is filled in and then INSERT it using perl DBI > > > > > > > > > > If any more information is needed please let me know. As far as i know i should be allowed to have null. > > > > > > > > > > TIA > > > > > Merritt > > > > > > > > > > CREATE TABLE slip_printer ( > > > > > id SERIAL PRIMARY KEY, > > > > > make VARCHAR(256) NOT NULL, > > > > > model VARCHAR(256) NOT NULL, > > > > > UNIQUE (make, model) > > > > > ); > > > > > > > > > > CREATE TABLE pc ( > > > > > id SERIAL PRIMARY KEY, > > > > > store INTEGER REFERENCES store (id) NOT NULL, > > > > > cpu_type INTEGER REFERENCES cpu_type (id) NOT NULL, > > > > > cpu_mhz INTEGER REFERENCES cpu_mhz (id) NOT NULL, > > > > > memory_type INTEGER REFERENCES memory_type (id) NOT NULL, > > > > > memory_amount INTEGER, /* amount of chips/sticks, not size in MB */ > > > > > hdd INTEGER REFERENCES hdd (id), > > > > > hdd_serial VARCHAR(256), > > > > > monitor INTEGER REFERENCES monitor (id) NOT NULL, > > > > > slip_printer INTEGER REFERENCES slip_printer (id), > > > > > report_printer INTEGER REFERENCES report_printer (id), > > > > > cash_drawer INTEGER REFERENCES cash_drawer (id) NOT NULL, > > > > > scanner INTEGER REFERENCES scanner (id) NOT NULL, > > > > > ups INTEGER REFERENCES ups (id), > > > > > modem INTEGER REFERENCES modem (id) > > > > > ); > > > > > > > > > -- Nigel J. Andrews
pgsql-general by date: