|
From: Justin B. <jgb...@gm...> - 2009-05-23 04:39:39
|
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
>
|