-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with day() function using Postgres
PostPosted: Sat May 09, 2009 12:38 pm 
Newbie

Joined: Sat May 09, 2009 12:23 pm
Posts: 1
Hello, i have a problem with day() function in as a WHERE clause.

My system is an Ubuntu, with JDK 1.6, PostgreSQL 8.2.11, Hibernate 3.3.1.

My Query is as simple as:

Code:
@NamedQuery(name = "findReservesBySalaDia", query = "select r from Reserva as r WHERE
       day(:diaHora) = day(r.diaHora))


Where :diaHora is a java.util.Date instance. As you can see i only want all Reserves that has been reserved at an specific day, no matter month nor year.

Ant what i gets is an exception:
Quote:
Caused by: org.postgresql.util.PSQLException: ERROR: function pg_catalog.date_part("unknown", "unknown") is not unique


Watching SQL generated by Hibernate:

Quote:
elect reserva0_.dboid as dboid2_, reserva0_.diaHora as diaHora2_, reserva0_.motiu as motiu2_, reserva0_.sala as sala2_, reserva0_.usuari as usuari2_ from Reserva reserva0_ where extract(day from ?)=extract(day from reserva0_.diaHora)


but if in postgres manual the function extract works like:

Code:
extract(hour from timestamp '2001-02-16 20:38:40')


it seems like the function is not properly converted, but i cannot ensure.

Anybody have any idea? Of course at least i can make it using a native query but i want to avoid that final solution.

Thank you very much for your help


Top
 Profile  
 
 Post subject: Re: Problem with day() function using Postgres
PostPosted: Mon Jun 22, 2009 6:45 pm 
Newbie

Joined: Sun Apr 10, 2005 2:20 am
Posts: 15
I am having the same problem here.

Quote:
"SEVERE: ERROR: function pg_catalog.date_part(unknown, unknown) is not unique"


This is caused by the same scenario. Hibernate generates the following for a statement containing 'year(?)':

extract(year from ?)

This would work:

extract(year from ?::DATE)

Also found the following thread:

http://archives.postgresql.org/pgsql-jd ... g00000.php

I tried this with the 8.1, 8.2 and 8.3 JDBC 3 drivers.


Top
 Profile  
 
 Post subject: Re: Problem with day() function using Postgres
PostPosted: Mon Oct 11, 2010 7:18 am 
Newbie

Joined: Mon Oct 11, 2010 7:07 am
Posts: 1
Sorry for bumping old thread. I just got this error message when migrating from MS-SqlServer 2005 to PostgreSQL 8.4.

The query is as simple as:
Code:
Issue.executeQuery(
    "select count(*) from Issue i where day(i.statusDate) = day(:date) and i.project.id = :id",
    [date:d.date,id:Long.parseLong(params.id)]
)


What can I do to fix this?


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

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.