Skip site navigation (1) Skip section navigation (2)

Foreign keys with values of zero rather than null

From: "Campbell, Lance" <lance(at)illinois(dot)edu>
To: <pgsql-admin(at)postgresql(dot)org>
Subject: Foreign keys with values of zero rather than null
Date: 2009-12-18 19:07:55
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-admin
I map data from rows in tables to objects in Java. When I map integers
in the database I map them to integer primitives in Java.  The challenge
I am running into is what do I do when a table has a integer foreign key
that is null.  Ideally when a table in PostgreSql has a foreign key that
does not exist I would like the value to be zero rather than null.  This
works really well for me because I NEVER use a key with the value of 0.


Is there some way for me to tell PostgreSql that a zero is the same as
null when using foreign keys that map to integers?  That way I can still
use cascade delete.  The only way for me to get around this issue is to
remove the foreign key constraint for cascade delete.


Any help would be appreciated.




Lance Campbell

Software Architect/DBA/Project Manager

Web Services at Public Affairs




pgsql-admin by date

Next:From: Lewis KapellDate: 2009-12-18 19:33:03
Subject: Backslashes in bytea values
Previous:From: FrancescDate: 2009-12-18 13:37:29
Subject: Fwd: Problems to connect to a postgreSQL 8.4 database on windows 2003 server

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group