From: Justin B. <jgb...@gm...> - 2009-05-26 04:33:16
|
Just like SQL, HaskellDB has the "isNull" operator. You can use that to test if a column is null. I've found the best way to use HaskellDB is to think how I would write a query in SQL, and then find the equivalents in HaskellDB. As for the optimized SQL, I agree. There isn't anything in the package that you aren't seeing. If you see opportunity for improvements please send a message or better yet, a patch! On Sat, May 23, 2009 at 1:43 AM, Mathijs Kwik <blu...@gm...> wrote: > Hi, > > Thanks for the quick reply. > I was affraid that fromNull thing was gonna be needed indeed. > While this works in this case, I'm not very happy with it. > NULL != 0, and there might be cases where all possible values are > allowed in a certain column (including 0). > Isn't it possible to do this the other way around? (tell the other, > mandatory field to become Just ...) > > Also, while I don't mind yet (since I like the idea of haskelldb very > much), the so-called optimized sql is horrible :) > Maybe some optimizations (things like using inner joins) should be > turned on? How can I do this? > > Thanks again, > Mathijs > > > > > On Sat, May 23, 2009 at 6:37 AM, Justin Bailey <jgb...@gm...> wrote: >> The error is telling you that you can't compare an "Int" to a "Maybe >> Int", which makes sense becuse one column can hold NULL or an int, >> while the other can only hold ints. Use the fromNull operator. >> Assuming group_id is the column which can be null, I think you want: >> >> let q = do { u <- table users; g <- table groups; restrict (g ! >> G.xid .==. fromNull (constant 0) (u ! U.group_id))} >> >> Justin >> >> On Fri, May 22, 2009 at 6:36 PM, Mathijs Kwik <blu...@gm...> wrote: >>> Hi all, >>> >>> I finally got haskelldb working. It took some time, but (after many >>> tries in the past) I got it. >>> I'm playing around with querying and I have a simple question: >>> >>> I have a table with a foreign key that can be NULL. >>> Now if I try to create an inner-join like restriction, I get a >>> type-mismatch, which I can understand, but couldn't figure out how to >>> solve it (it's a little late here :) >>> >>> let q = do { u <- table users; g <- table groups; restrict (g!G.xid >>> .==. u!U.group_id)} >>> >>> <interactive>:1:4: >>> Couldn't match expected type `Int' >>> against inferred type `Maybe Int' >>> Expected type: Expr Int >>> Inferred type: Expr (Maybe Int) >>> When using functional dependencies to combine >>> Select (Attr f a) (Rel r) (Expr a), >>> arising from the dependency `f r -> a' >>> in the instance declaration at <no location info> >>> Select (Attr U.Group_id (Maybe Int)) (Rel U.Users) (Expr Int), >>> arising from a use of `!' at <interactive>:1:97-107 >>> When generalising the type(s) for `q' >>> >>> What would be the correct way to fix this? >>> >>> Thanks, >>> Mathijs >>> >>> ------------------------------------------------------------------------------ >>> Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT >>> is a gathering of tech-side developers & brand creativity professionals. Meet >>> the minds behind Google Creative Lab, Visual Complexity, Processing, & >>> iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian >>> Group, R/GA, & Big Spaceship. http://www.creativitycat.com >>> _______________________________________________ >>> Haskelldb-users mailing list >>> Has...@li... >>> https://lists.sourceforge.net/lists/listinfo/haskelldb-users >>> >> > |