-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Incorrect SQL generation in Sybase dialect
PostPosted: Wed Sep 27, 2006 5:05 am 
Newbie

Joined: Wed Sep 27, 2006 4:33 am
Posts: 1
Hibernate version: 3.2cr2 (and earlier)
Name and version of the database I am using: Sybase 12.5
HQL:
select reasonCode, sum(credit), sum(debet) from PLog
group by hour(timestamp)
The generated SQL:
select
plog0_.REASON_CODE as col_0_0_,
sum(plog0_.CREDIT) as col_1_0_,
sum(plog0_.DEBET) as col_2_0_
from
P_LOG plog0_
group by
extract(hour
from
plog0_.TIMESTAMP)
-----------------
I think this is an error in Sybase dialect. Following SQL is not recognized as valid by jdbc driver (I have tried both JConnect 5.5 and jtds 1.2):

extract(hour from plog0_.TIMESTAMP)

Parse error is "Incorrect syntax near the keyword 'from'". Although this is valid syntax according to standards, Sybase (at least 12.5 and earlier) does not support it and I have found no mention of 'extract' in Sybase's documentation.

Usual workaround for extracting date components (one that I have seen before) is to use a hack with conversing date to text format and selecting required part of that text. For example hour can be selected as

convert(char(2), timestampField, 8)

In my opinion this bug and it affects HQL functions second(...), minute(...), hour(...), day(...), month(...), year(...).

Should I submit a bug report or did I miss something?



PS Funnily enough that http://sqlzoo.net offers following SQL in the same syntax for selecting date components:

SELECT EXTRACT(YEAR FROM wk),
EXTRACT(MONTH FROM wk),
EXTRACT(DAY FROM wk)
FROM totp WHERE song='Rio'

And in turn fails to execute it with the same error :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.