On Sep 27, 2011, at 1:12 AM, Nathan Robertson wrote:

> On Mon, Sep 26, 2011 at 11:05 PM, Michael Bayer wrote:
>> On Sep 26, 2011, at 2:50 AM, Nathan Robertson wrote:
>> 
>>>       Column('custid', Integer, Sequence('test.customer_custid_seq'), 
>>> primary_key=True),
>> 
>> for the Sequence, as with all schema items, you need to specify the "schema" 
>> portion separately so that SQLAlchemy knows where each token starts and ends:
>> 
>> Sequence("customer_custid_seq", schema="test")
> 
> Actually, I just noticed that the same thing doesn't apply to foreign
> keys. I've actually got code in production which does something like:
> 
> Column('custid', BigInteger, ForeignKey('test.customer.custid'),
> primary_key=True)
> 
> What's the reason for the distinction requiring the schema to be split
> out in a Sequence, but not in the case of a ForeignKey?

OK that's a great question.   This is a case where looking at it from my 
perspective, I'd never see it that way, but from someone coming into it from 
the API usage side, yeah that seems pretty obvious.     Maybe ForeignKey and 
ForeignKeyConstraint should accept a "schema" argument instead, though if that 
were the case I'd deprecate the other method since we try not to have multiple 
ways to do something...but that would be hard at this point since there's 
thousands of apps that do it the current way.    Maybe having "schema" as an 
option and just having two ways to do it....arg.   Would have to think about 
it.  I added http://www.sqlalchemy.org/trac/ticket/2288 for this idea.

Basically from the ForeignKey perspective it's an element of a Table, and the 
directives to generate a foreign key constraint don't include the schema where 
the constraint itself lives; that's part of its parent Table and is already 
handled.  The column it references, that belongs to a table which may have a 
schema, but ForeignKey doesn't need the separate schema information because it 
ultimately is pointing to an actual Column object on another Table, which also 
has "schema" taken care of. The string "x.y.z" sent to ForeignKey is only used 
internally to locate another Table/Column within the MetaData.   Whereas Table, 
Sequence, we need to quote the individual elements so "schema" has always been 
separate at that level.


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

Reply via email to