From 10e97b55c986fce21179b31ab020f8a248830d49 Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Tue, 15 Feb 2011 23:21:11 +0000 Subject: [PATCH] PostgreSQL gets very confused when date_part() is used in a GROUP BY and the part bit isn't a constant. It doesn't recognize the selected values as being identical to the grouped-by values, and throws an error. So we use a literal here. --- .../java/com/samskivert/depot/impl/PostgreSQLBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/samskivert/depot/impl/PostgreSQLBuilder.java b/src/main/java/com/samskivert/depot/impl/PostgreSQLBuilder.java index 3e6ce94..e357b7d 100644 --- a/src/main/java/com/samskivert/depot/impl/PostgreSQLBuilder.java +++ b/src/main/java/com/samskivert/depot/impl/PostgreSQLBuilder.java @@ -87,8 +87,8 @@ public class PostgreSQLBuilder @Override public Void visit (DatePart exp) { - return appendFunctionCall( - "date_part", Exps.value(translateDatePart(exp.getPart())), exp.getArg()); + String datePart = "'" + translateDatePart(exp.getPart()) + "'"; + return appendFunctionCall("date_part", Exps.literal(datePart), exp.getArg()); } @Override