update from subquery / aggregate

82 views
Skip to first unread message

Vincent Côté-Roy

unread,
Jan 25, 2011, 5:04:38 PM1/25/11
to squ...@googlegroups.com
Hi,

I'm trying to figure out the syntax to update a row from a subquery to
another table. In sql it would look like this:

update Eval set totalScore = (select sum(score) from answer where
evalid = eval.id) where id = [xyz]

I tried the following:

update (evals) (e =>
where (e.id === id)
set (e.totalScore := from(answers)(a => where(a.evalId === [xyz])
compute (sum(a.score)))
)

This results in this error:
could not find implicit value for evidence parameter of type
(org.squeryl.dsl.Measures[Option[org.squeryl.PrimitiveTypeMode.IntType]]])
=> org.squeryl.dsl.ast.TypedExpressionNode[org.squeryl.PrimitiveTypeMode.IntType]


For testing purposes I also tried removing the aggregate, but it can't
get it to work either:

update (evals) (e =>
where (e.id === id)
set (e.totalScore := from(answers)(a => where(a.evalId === id)
select (a.score))
)

This gives me a similar error:
could not find implicit value for evidence parameter of type
(org.squeryl.Query[Int]) =>
org.squeryl.dsl.ast.TypedExpressionNode[org.squeryl.PrimitiveTypeMode.IntType]

Am I getting the syntax wrong or is this not supported right now? I
couldn't find a similar sample in the docs.

Thanks

Vincent

Maxime Lévesque

unread,
Jan 25, 2011, 10:56:35 PM1/25/11
to squ...@googlegroups.com

Subqueries in set functions are not supported,

please open a ticket : http://www.assembla.com/spaces/squeryl/tickets

Thanks

2011/1/25 Vincent Côté-Roy <vinc...@jucent.com>

Vincent Côté-Roy

unread,
Jan 26, 2011, 7:47:51 AM1/26/11
to squ...@googlegroups.com
Hi Maxime,

I tried but I don't seem to have the option to do so. There's no "new
ticket" button after I login.

Thanks,

Vincent


2011/1/25 Maxime Lévesque <maxime....@gmail.com>:

--

Vincent Côté-Roy

Michael Gottschalk

unread,
Jan 26, 2011, 7:54:47 AM1/26/11
to Squeryl
Hi Vincent,

On 26 Jan., 13:47, Vincent Côté-Roy <vincen...@jucent.com> wrote:
> Hi Maxime,
>
> I tried but I don't seem to have the option to do so. There's no "new
> ticket" button after I login.

you have to watch the space for being able to create a new ticket.
There should be a link "Watch this space" somewhere.

Cheers,
Michael

> 2011/1/25 Maxime Lévesque <maxime.leves...@gmail.com>:
>
>
>
>
>
> > Subqueries in set functions are not supported,
>
> > please open a ticket :http://www.assembla.com/spaces/squeryl/tickets
>
> > Thanks
>
> > 2011/1/25 Vincent Côté-Roy <vincen...@jucent.com>

Vincent Côté-Roy

unread,
Jan 26, 2011, 8:16:32 AM1/26/11
to squ...@googlegroups.com
Hi Michael,

I did and I still can't. I seem to have only read-only access to tickets.

--

Vincent Côté-Roy

Maxime Lévesque

unread,
Jan 29, 2011, 6:30:43 PM1/29/11
to squ...@googlegroups.com

Just pushed support for subqueries in partial update set clause :

 https://github.com/max-l/Squeryl/commit/e75ddecf4a0855771dd569b4c4df4e23fde2133e

please reopen the ticket if necessary.

2011/1/26 Vincent Côté-Roy <vinc...@jucent.com>

Vincent Côté-Roy

unread,
Jan 30, 2011, 10:57:37 PM1/30/11
to squ...@googlegroups.com
Thanks! I'll try it tomorrow.

2011/1/29 Maxime Lévesque <maxime....@gmail.com>:

--

Vincent Côté-Roy

ÆtherSurfer

unread,
Jun 3, 2015, 10:45:24 AM6/3/15
to squ...@googlegroups.com

David Whittaker

unread,
Jun 3, 2015, 12:39:54 PM6/3/15
to squ...@googlegroups.com
:)  So it seems there should be support for this.

Ummmm.... Max?

--
You received this message because you are subscribed to the Google Groups "Squeryl" group.
To unsubscribe from this group and stop receiving emails from it, send an email to squeryl+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ÆtherSurfer

unread,
Jun 11, 2015, 10:45:50 AM6/11/15
to squ...@googlegroups.com
I eventually settled on this workaround

update(widgets) (
  w=>
    where(w.id === 2)
    set(w.foo := from(widgets)(prevW => where(prevW.id === 1) compute(min(foo))))
)

http://stackoverflow.com/a/30783999/263306
Reply all
Reply to author
Forward
0 new messages