Adding support for WEEK as a date part in EXTRACT function

186 views
Skip to first unread message

Prashant Bhat

unread,
Oct 5, 2012, 4:47:08 AM10/5/12
to h2-da...@googlegroups.com
Hi,

We are using H2 Database in our application, but based on requirement of some users PostgreSQL is used. And we use JPA to be compatible with both the databases, but some of the reports use native sql queries. One of the queries that uses EXTRACT(WEEK FROM dateColumn) is not compatible with H2, as it supports WK and WW which are not supported in Postgresql.

We've made the following change to Function.java to add this option and the attached patch also updates help.csv files. I hope this can be integrated into H2 codebase.

Thanks & Best Regards,
Prashant


Index: src/main/org/h2/expression/Function.java
===================================================================
--- src/main/org/h2/expression/Function.java    (revision 4381)
+++ src/main/org/h2/expression/Function.java    (working copy)
@@ -129,6 +129,7 @@
         DATE_PART.put("SQL_TSI_WEEK", Calendar.WEEK_OF_YEAR);
         DATE_PART.put("WW", Calendar.WEEK_OF_YEAR);
         DATE_PART.put("WK", Calendar.WEEK_OF_YEAR);
+        DATE_PART.put("WEEK", Calendar.WEEK_OF_YEAR);
         DATE_PART.put("DAY", Calendar.DAY_OF_MONTH);
         DATE_PART.put("DD", Calendar.DAY_OF_MONTH);
         DATE_PART.put("D", Calendar.DAY_OF_MONTH);
h2-extract-week.patch

Thomas Mueller

unread,
Oct 14, 2012, 8:44:16 AM10/14/12
to h2-da...@googlegroups.com
Hi,

Thanks a lot for the patch! It is now committed and will be included in the next release. I have also added a simple test case and a change log entry, see http://code.google.com/p/h2database/source/list for details.

Regards,
Thomas





--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To view this discussion on the web visit https://groups.google.com/d/msg/h2-database/-/ryzFLKw46TQJ.
To post to this group, send email to h2-da...@googlegroups.com.
To unsubscribe from this group, send email to h2-database...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.

Prashant Bhat

unread,
Oct 15, 2012, 1:49:37 AM10/15/12
to h2-da...@googlegroups.com
Hi Thomas,

Thanks a lot. In future, I'll try to include the test case also.

Regards,
Prashant
Reply all
Reply to author
Forward
0 new messages