I'm trying to query record filtering on the date (documentation for date)
select * from InstallationFee where infinite OR (date() >= dateFrom and date() <= dateTo)
The query returns the following error in the studio:
java.lang.ClassCastException: com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField cannot be cast to com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition
Here is the stack trace in the JAVA api
com.orientechnologies.orient.core.exception.OCommandExecutionException: Error on execution of command: sql.select * from InstallationFee where (infinite OR date() >= dateFrom and date() <= dateTo)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.executeCommand(OAbstractPaginatedStorage.java:1190)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.command(OAbstractPaginatedStorage.java:1173)
at com.orientechnologies.orient.core.sql.query.OSQLQuery.run(OSQLQuery.java:71)
at com.orientechnologies.orient.core.sql.query.OSQLSynchQuery.run(OSQLSynchQuery.java:85)
at com.orientechnologies.orient.core.query.OQueryAbstract.execute(OQueryAbstract.java:33)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.command(ONetworkProtocolBinary.java:1178)
at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.executeRequest(ONetworkProtocolBinary.java:385)
at com.orientechnologies.orient.server.network.protocol.binary.OBinaryNetworkProtocolAbstract.execute(OBinaryNetworkProtocolAbstract.java:216)
at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:65)
Caused by: java.lang.ClassCastException: com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField cannot be cast to com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition
at com.orientechnologies.orient.core.sql.OFilterAnalyzer.analyzeUnion(OFilterAnalyzer.java:195)
at com.orientechnologies.orient.core.sql.OFilterAnalyzer.analyzeOrFilterBranch(OFilterAnalyzer.java:80)
at com.orientechnologies.orient.core.sql.OFilterAnalyzer.analyzeMainCondition(OFilterAnalyzer.java:58)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.searchForIndexes(OCommandExecutorSQLSelect.java:1454)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.searchInClasses(OCommandExecutorSQLSelect.java:765)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLResultsetAbstract.assignTarget(OCommandExecutorSQLResultsetAbstract.java:194)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.assignTarget(OCommandExecutorSQLSelect.java:438)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.executeSearch(OCommandExecutorSQLSelect.java:420)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.execute(OCommandExecutorSQLSelect.java:391)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.execute(OCommandExecutorSQLDelegate.java:64)
at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.executeCommand(OAbstractPaginatedStorage.java:1184)
I tried a different approaches in the studio, but all resulted with the error presented above. Here are a few:
Using sysdate
select * from InstallationFee where infinite OR (sysdate("yyyy-MM-dd") >= dateFrom and sysdate("yyyy-MM-dd") <= dateTo)
Using between (documentation)
select * from InstallationFee where infinite OR date("yyyy-MM-dd") between dateFrom and dateTo)
Am I missing something? or Is there a way around this problem?
I believe the error comes from:
... where infinite ...
It should be:
... where infinite = true ...
Related
I currently have a QUERY function which is set up based on a start date cell and an end date cell, formula as below:
=QUERY(Haulage!$A$3:$L$29," Select * Where A >= date """&text('2022 Stats'!S1, "yyyy-mm-dd")&""" AND A <= date """&text('2022 Stats'!T1, "yyyy-mm-dd")&"""")
This is working fine but I would like to adapt it so I can also narrow the query down further with the use of a dropdown. I have the following IF formula for this:
=IF('2022 Stats'!V1="All TOCs",""," AND LOWER(K) = LOWER('"&'2022 Stats'!V1&"') " )
This seems to yield the correct results but I am struggling to get the two to work together......
Link to sheet: https://docs.google.com/spreadsheets/d/1wTWuvFwMTqJ-sjIZbXWpGOS1WKwpODj2R8KAzqlqkuw/edit?usp=sharing
Try:
=QUERY(Haulage!A3:L29,
"where A >= date '"&TEXT('2022 Stats'!S1, "yyyy-mm-dd")&"'
and A <= date '"&TEXT('2022 Stats'!T1, "yyyy-mm-dd")&"'"&
IF('2022 Stats'!V1="All TOCs",,"
and lower(K) = '"&LOWER('2022 Stats'!V1)&"'"))
I'm trying to select data between an hour range, without using extract to be able to use the indexes in the table. I do the query like this:
SELECT *
FROM activities
WHERE "dateParam"::timestamp >= '21:00:00'::timestamp
AND "dateParam"::timestamp <= '23:00:00'::timestamp;
But I get an 22007 state and it doesnt work, how could I be able to do it?
Try:
SELECT *
FROM activities
WHERE "dateParam"::timestamp >= current_date + '21:00:00'::time
AND "dateParam"::timestamp <= current_date + '23:00:00'::time;
A timestamp needs a date portion so add it.
I am trying to write dynamic sql query in metabase-
I added date filter like that (using snowflake for query):
select * from my_table where date > {{date_filter}}
after that I needed to set default value of yesterday to date_filter, so I write this:
select * from my_table where date > [[{{date_filter}} #]]dateadd(DAY, -1, GETDATE())
and it worked, when I ran this query- I got the right output.
BUT- when I changed the date in the calendar that metabase provided for date types- I got this error:
SQL compilation error: syntax error line 1 at position 142 unexpected '#D'. syntax error line 1 at position 156 unexpected '-'. syntax error line 1 at position 172 unexpected '('.
How can I change date_filter default value without getting this error?
finally found a workaround that solve the problem.
in UI settings, define date_filter as REQUIRED and assign static default value- for example 01.01.2015 if my table contains data starting of 2016.
in sql query- I wrote that:
select * from my_table where date > case when year({{date_filter}}) = 2015 then dateadd(DAY, -1, GETDATE()) else {{date_filter}} end
which means:
if I won't select any date in date_filter calender- date_filter year value will be 2015 (as I defined date_filter = 01.01.2015) so I will compare DATE against dateadd(DAY, -1, GETDATE()).
but if I WILL select value in date_filter calender, then year(date_filter) will be different than 2015 (as I said, I won't choose date before 2016 because I have no data before 2016 in my table) so I will compare DATE against {{date_filter}} value which I just selected.
spark.sql("""SELECT CAST('22:00:00' AS INTERVAL HOUR TO SECOND)""").show()
I am executing the above query but getting the below error
ERROR : ParseException:
missing ')' at 'HOUR'(line 1, pos 35)
INTERVAL HOUR TO SECOND sql syntax format:
select INTERVAL '22:00:00' HOUR TO SECOND
I am having trouble using spring-boot CrudRepository,What I want to do is to look up the data for a period of time
I make a query by this and result is ok
List<T> findByTimestampAfter(#Param("timestamp") Date start)
This is also ok
List<T> findByTimestampBefore(#Param("timestamp") Date end)
But I tried the following three methods do not work:
List<T> findByTimestampBetween(#Param("timestamp") Date start,#Param("timestamp") Date end)
List<T> findByTimestampAfterAndTimestampBefore(#Param("timestamp") Date start,#Param("timestamp") Date end)
List<T> findByTimestampGreaterThanEqualAndTimestampLessThanEqual(#Param("timestamp") Date start,#Param("timestamp") Date end)
What I want to get is more than 100 data in the time frame, but there is only one which timestamp euqal end
And i try execute this sql statementselect:
select * from exchange where timestamp > "2018-01-02 17:30:00" AND timestamp < "2018-01-02 17:48:00";
i can see the more than 100 data.
I think I can not solve this problem
The keyword between is not supported inside method name. You should define your custom query, for example:
#Query("select * from exchange where timestamp > ?1 AND timestamp < ?2")
Object[] findByTimeCustomQuery(Date dFrom, Date dTo);
See the query executing from the jpa automatically.If you just use proper debugging logger .Also tell the proper result achieved from above three methods.