I'm rather new to Postgresql, but hope someone here can help me out. Even
though I am specifying foreign and primary keys in my tables as I create
them, the foreign key options, such as CASCADE and NO ACTION, don't seem to
be working. I am allowed to change primary keys with no effect on the
foreign keys and with no error messages generated. I am using PHP3 and
postgresql 6.5.3 on Linux. I have tried using Bruce Momijian's example
code verbatim, and still didn't seem to have any kind of foreign key
constraints operating. Is this a result of some kind of
installation/configuration problem? Below are sections of the PHP Code I
am using to try Bruce's examples, though I don't run this all at once ( I
ran it exactly in the order in which Bruce gave it):
$connection = pg_connect("dbname=intranet user=intranet port=5432");
pg_exec($connection, "CREATE TABLE primarytest (col INTEGER PRIMARY KEY)");
pg_exec($connection, "CREATE TABLE foreigntest (col2 INTEGER REFERENCES
primarytest ON UPDATE CASCADE ON DELETE NO ACTION)");
pg_exec($connection, "INSERT INTO primarytest VALUES(1)");
pg_exec($connection, "INSERT INTO foreigntest VALUES(1)");
$update = pg_exec($connection, "UPDATE primarytest SET col=2");
pg_exec($connection, "DELETE FROM primarytest");
$result = pg_exec($connection, "SELECT * FROM foreigntest");
print("<table border=1 cellpadding=2>\n");
for($i = 0; $i < pg_numrows($result); $i++)
{
$thisrow = pg_fetch_row($result,$i);
print
("<tr><td>$i</td><td>$thisrow[0]</td><td>$thisrow[1]</td></tr>\n");
}
print("</table>\n");
pg_freeresult($result);
Your help is greatly appreciated.
John Clayton
Knowledge Manager
Site Builder
First Light Communications
55 John St. 8th Floor
New York, NY 10038
(212) 766-2380 x222