Hello Samantha,
Here's the answer I also gave on Stack Overflow:
Unfortunately, there is (currently, as of jOOQ 3.2) no way to typesafely
dereference the I column from your derived table e, as there is no way the
Java compiler can know that there is an I column. You will have to resort
to unsafe methods:
// Enforcing typesafety using
coercion:.join(e).on(s.NAME.equal(e.field("I").coerce(String.class))
// Circumventing typesafety using raw
types.join(e).on(s.NAME.equal((Field) e.field("I")))
A bit more typesafety can be achieved by reusing the I field as such:
Source s = SOURCE.as("s");Field<String> I =
SOURCE.ID.as("I");TableLike<?> e = create.select()
.from(SOURCE)
.where(SOURCE.NAME.isNotNull()
.asTable().as("e");
create.selectCount()
.from(s)
.join(e)
.on(s.NAME.equal(e.field(I)))
.fetchOne().value1();
From:
http://stackoverflow.com/a/20992632/521799
2014/1/7 Samantha Klonaris <[email protected]>
> This is my sql statement:
>
> select count(*) from source s
> join(select id as I from source where name is not null) e
> on s.name = e.I
>
> Here is what I have in java
>
> Source s = SOURCE.as("s");
> TableLike<?> e = create.select(SOURCE.ID.as("I"))
> .from(SOURCE)
> .where(SOURCE.NAME.isNotNull()
> .asTable().as("e");
>
> create.selectCount()
> .from(s)
> .join(e)
> .on(s.NAME.equal(e.I))
> .fetchOne().value1();
>
> I think that TableLike is not the right type because I get an error when I
> try to do e.I
>
> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
You received this message because you are subscribed to the Google Groups "jOOQ
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.