which join are u mentioning? and which result u want to save? the query itself or the objects it returns after execution?
q = query(Line).join( Fiber, ...condition ).filter(....) if ... return q.filter( 123...) else: return q.filter( 456...) building that q is not expensive; saving it is fine but beware when sessions close/open etc. svilen On Tuesday 20 January 2009 16:33:16 Boudewijn Ector wrote: > On Tue, Jan 20, 2009 at 8:24 AM, <a...@svilendobrev.com> wrote: > > mmh, cant really grasp what u want to do. > > what are Line.* attributes? > > > > .filter does and(), so this can be simplified: > > q = query(Line).filter( models.Line.LineDiscarded == > > LineDiscarded ) if ...: > > return q.filter( sites...) > > else: > > return q.filter( sites...) > > That will probably work fine, but I'd like to join Fiber and Line > together, and save the result of the join itself. > The definition of Line: > > fiberdb=# \d "Line"; > Table "public.Line" > Column | Type > > | Modifiers > > ----------------------------+-----------------------------+-------- >------------------------------------------------- LineName > | character varying(50) | not null ProviderName > | character varying(50) | Length > | integer | not null default > nextval('"Line_Length_seq"'::regclass) > Type | character varying(50) | > MeasurementReport | text | > Comment | text | > LineDiscarded | character(1) | > LineNamesReplacingThisLine | text | > EndOfContractDate | timestamp without time zone | > LineNameSURFnet | character varying(50) | > SiteLocationCodeA | character varying(50) | > SiteLocationCodeB | character varying(50) | > last_updated | timestamp with time zone | > last_updated_by | character varying(50) | > GeoObjectID | integer | > importedFromWKT | character(1) | > ThirdPartyName | character varying(50) | > GeoData | geometry | > Indexes: > "PRI_Line" PRIMARY KEY, btree ("LineName") > "FKI_Line_GeoObject" btree ("GeoObjectID") > "FKI_Line_Provider" btree ("ProviderName") > "FKI_Line_Site" btree ("SiteLocationCodeA") > "FKI_Line_SiteA" btree ("SiteLocationCodeA") > "FKI_Line_SiteB" btree ("SiteLocationCodeB") > Check constraints: > "enforce_dims_Data" CHECK (ndims("GeoData") = 3) > "enforce_srid_Data" CHECK (srid("GeoData") = 4326) > Foreign-key constraints: > "FK_Line_GeoObject" FOREIGN KEY ("GeoObjectID") REFERENCES > "GeoObject"("GeoObjectID") ON UPDATE CASCADE ON DELETE CASCADE > "FK_Line_Provider" FOREIGN KEY ("ProviderName") REFERENCES > "Provider"("ProviderName") ON UPDATE CASCADE ON DELETE RESTRICT > "FK_Line_SiteA" FOREIGN KEY ("SiteLocationCodeA") REFERENCES > "Site"("SiteLocationCode") ON UPDATE CASCADE ON DELETE RESTRICT > "FK_Line_SiteB" FOREIGN KEY ("SiteLocationCodeB") REFERENCES > "Site"("SiteLocationCode") ON UPDATE CASCADE ON DELETE RESTRICT > > > > So, I get the SiteLocationCodeA and SiteLocationCodeB. I need to > retrieve all fibers between them (because I'd like to have a look > at the FiberInUse property between two SiteLocationCodes). > So I join Fiber and Line using the LineName as key. > Now, I should be able to have a look which Lines between A and B > have Fibers which are not in use. > > But, more interesting things and filters might come in handy, in my > search function. So I'd prefer to save the result of the join into > a variable, so I don't need to do the join in every case of my > search function. > > > That's why. > > Cheers, > > Boudewijn Ector > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---