You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by metcox <me...@gmail.com> on 2007/07/13 10:51:48 UTC

row value constructor syntax (tuple syntax)

Hi all,

I've got trouble with the following request:

from ResultAnnotation ra where
ra.group.job.name='XPLE-B34' and ra.severity='FAILURE'
and not (ra.target, ra.detailTarget) in (select rb.target,
rb.detailTargetfrom ResultAnnotation rb where
rb.group.job.name='XPLE-B33' and rb.severity='FAILURE')


and I get this exception:

org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(
SQLStateConverter.java:67)
    at org.hibernate.exception.JDBCExceptionHelper.convert(
JDBCExceptionHelper.java:43)
    at org.hibernate.loader.Loader.doList(Loader.java:2223)
...
Caused by: java.sql.SQLSyntaxErrorException: Syntax error: Encountered ","
at line 1, column 595.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown
Source)
    at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown
Source)
    at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown
Source)
    at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown
Source)
    at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown
Source)
    at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown
Source)
    at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown
Source)
....
Caused by: org.apache.derby.impl.jdbc.EmbedSQLException: Syntax error:
Encountered "," at line 1, column 595.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
Source)
    at
org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown
Source)
...

What am I doing wrong ?

It seems the problem comes  from the use of tuple
Does Derby support row value constructor syntax (tuple syntax)?
If not, how can I rewrite my query to bypass this limitation?

thanks

Mathieu

Re: row value constructor syntax (tuple syntax)

Posted by metcox <me...@gmail.com>.
2007/7/16, Knut Anders Hatlen <Kn...@sun.com>:
> metcox <me...@gmail.com> writes:
>
> > Hi all,
> >
> > I've got trouble with the following request:
> >
> > from ResultAnnotation ra where
> > ra.group.job.name='XPLE-B34' and ra.severity='FAILURE'
> > and not (ra.target, ra.detailTarget) in (select rb.target,
> > rb.detailTargetfrom ResultAnnotation rb where
> > rb.group.job.name='XPLE-B33' and rb.severity='FAILURE')
> >
> >
> > and I get this exception:
> [...]
> > Caused by: org.apache.derby.impl.jdbc.EmbedSQLException: Syntax error:
> > Encountered "," at line 1, column 595.
> >    at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
> > Source)
> >    at
> > org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown
> > Source)
> > ...
> >
> > What am I doing wrong ?
> >
> > It seems the problem comes  from the use of tuple
> > Does Derby support row value constructor syntax (tuple syntax)?
> > If not, how can I rewrite my query to bypass this limitation?
>
> You could perhaps use WHERE NOT EXISTS, like this:
>
> SELECT * FROM ResultAnnotation ra WHERE
>   ra.group.job.name = 'XPLE-B34' AND ra.severity = 'FAILURE'
> AND NOT EXISTS
>   (SELECT rb.target, rb.detailTarget FROM ResultAnnotation rb WHERE
>      rb.group.job.name = 'XPLE-B33' AND rb.severity = 'FAILURE'
>    AND rb.target = ra.target AND rb.detailTarget = ra.detailTarget)

I get the following exception:

java.sql.SQLException: Subquery is only allowed to return a single column.
     at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
Source)
     at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown
Source)
...

but I don't need to select target and detailTarget in the subquery. So
after removing the select in the subquery it works.

from ResultAnnotation ra where
  ra.group.job.name = 'XPLE-B34' and ra.severity = 'FAILURE'
  and not exists (from ResultAnnotation rb where
    rb.group.job.name = 'XPLE-B33' and rb.severity = 'FAILURE'
    and rb.target = ra.target and rb.detailTarget = ra.detailTarget)

thanks a lot.

Mathieu

> --
> Knut Anders
>

Re: row value constructor syntax (tuple syntax)

Posted by Knut Anders Hatlen <Kn...@Sun.COM>.
metcox <me...@gmail.com> writes:

> Hi all,
>
> I've got trouble with the following request:
>
> from ResultAnnotation ra where
> ra.group.job.name='XPLE-B34' and ra.severity='FAILURE'
> and not (ra.target, ra.detailTarget) in (select rb.target,
> rb.detailTargetfrom ResultAnnotation rb where
> rb.group.job.name='XPLE-B33' and rb.severity='FAILURE')
>
>
> and I get this exception:
[...]
> Caused by: org.apache.derby.impl.jdbc.EmbedSQLException: Syntax error:
> Encountered "," at line 1, column 595.
>    at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
> Source)
>    at
> org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown
> Source)
> ...
>
> What am I doing wrong ?
>
> It seems the problem comes  from the use of tuple
> Does Derby support row value constructor syntax (tuple syntax)?
> If not, how can I rewrite my query to bypass this limitation?

You could perhaps use WHERE NOT EXISTS, like this:

SELECT * FROM ResultAnnotation ra WHERE
  ra.group.job.name = 'XPLE-B34' AND ra.severity = 'FAILURE'
AND NOT EXISTS
  (SELECT rb.target, rb.detailTarget FROM ResultAnnotation rb WHERE
     rb.group.job.name = 'XPLE-B33' AND rb.severity = 'FAILURE'
   AND rb.target = ra.target AND rb.detailTarget = ra.detailTarget)

-- 
Knut Anders