I have two tables, SystemVariables and VariableOptions. SystemVariables is 
self-explanatory, and VariableOptions contains all of the possible values for 
all of the variables.

VariableOptions has a foreign key, variable_id, which states which variable it 
is an option for. SystemVariables has a foreign key, choice_id, which states 
which option is the currently selected one.

I've gotten around the cyclic relationship using use_alter on choice_id, and 
post_update on SystemVariables' choice relationship. However, I would like to 
add an extra database constraint that will ensure that choice_id is valid. The 
logic I need, assuming that sysVar represents a row in the SystemVariables 
table, is basically:

                VariableOptions[sysVar.choice_id].variable_id == sysVar.id

But I don't know how to construct this kind of constraint using SQL, 
declarative, or any other method. If necessary I could just validate this at 
the application level, but I'd like to have it at the database level if 
possible. I'm using Postgres 9.1.

Is this possible?

Thanks,
Cameron Jackson
Engineering Intern
Air Operations
Thales Australia
Thales Australia Centre, WTC Northbank Wharf, Concourse Level,
Siddeley Street, Melbourne, VIC 3005, Australia
Tel: +61 3 8630 4591
[email protected]<mailto:[email protected]> | 
www.thalesgroup.com.au<http://www.thalesgroup.com.au>


-------------------------------------------------------------------------
DISCLAIMER: This e-mail transmission and any documents, files and 
previous e-mail messages attached to it are private and confidential.  
They may contain proprietary or copyright material or information that 
is subject to legal professional privilege.  They are for the use of 
the intended recipient only.  Any unauthorised viewing, use, disclosure, 
copying, alteration, storage or distribution of, or reliance on, this 
message is strictly prohibited.  No part may be reproduced, adapted or 
transmitted without the written permission of the owner.  If you have 
received this transmission in error, or are not an authorised recipient, 
please immediately notify the sender by return email, delete this 
message and all copies from your e-mail system, and destroy any printed 
copies.  Receipt by anyone other than the intended recipient should not 
be deemed a waiver of any privilege or protection.  Thales Australia 
does not warrant or represent that this e-mail or any documents, files 
and previous e-mail messages attached are error or virus free.  

-------------------------------------------------------------------------

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to