I have an attribute of type instant and I want to query for the year.
[:find ?year
:where
[?t :x/date ?date]
[((fn [dt] (+ (.getYear dt) 1900)) ?date) ?year]]
Is there a better way to do this query?
Related
I'm using state_window syntax in TDengine database.
My SQL statement is:
select t.*
from (
select ts,
tbname as app_id,
tenant_name,
queue_code,
task_name,
sum(allocated) as allocated
from yarn
where ts > now - 6m
partition by ts,tbname,tenant_name,queue_code,task_name
) t
partition by ts, app_id, tenant_name, queue_code, task_name
state_window((CASE WHEN allocated > 100 THEN 1 ELSE 0 END));
Then I encountered an error report:
DB error: Window query not supported, since the result of subquery not
include valid timestamp column
I don't particularly understand its meaning, and how to fix the problem.
I have a datetime field in my model. In a query I want to select all rows created on a specific day/date (the time doesn't matter). What is the simplest way of doing that in CakePHP 3.8 ?
Per other answers, use of a custom function to cast the column with MySQL DATE() may slow your query down at scale. Besides, there's probably nothing simpler than plain arrays to build conditions:
$query = $this->YourTable->find()
->where([
'date_field >=' => '2020-01-01 00:00:0', // Or pass a Time() object..
'date_field <' => '2020-01-02 00:00:00',
]);
This kind of stuff is covered in the Query Builder docs.
How would one use the MSSQL 2016 AT TIMEZONE feature from Entity Framework?
In other words, how to generate
SELECT MyTimestamp AT TIME ZONE 'Central European Standard Time' FROM MyTable
by LINQ in entity framework ? Is it even supported yet ? Can one extend Entity Framework manually for this feature ?
There is always the option of creating a database-view with a time-zone column, but ideally I would like to avoid this extra view.
Couldn't you use a "model-defined function" in EF to create a functional expression that does at time zone thingy?
https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/ef/language-reference/how-to-call-model-defined-functions-in-queries
<Function Name="TZ" ReturnType="Edm.DateTime">
<Parameter Name="date" Type="Edm.DateTime" />
<DefiningExpression>
date AT TIME ZONE 'Central European Standard Time'
</DefiningExpression>
</Function>
[EdmFunction("YourModel", "TZ")]
public static int TZ(DateTime date)
{
throw new NotSupportedException("Direct calls are not supported.");
}
#C:
from m as Mytable select new {TZ(s.MyTimestamp)};
Overview of situation: I have two databases (one is DB2 and one is MSSQL) and I am using an SSIS package to feed from one to the other via jobs. In our SQL table, datetime fields were set up as SmallDateTime (years and years ago, cannot change at this point in time yet to DateTime). We are now getting dates that are coming through as year 2099 (1/1/2099) which fails as SmallDateTime can only go MaxDate of 06/06/2079 11:59:59.
My/our solution is to use the Derived Column transform to check the date, and if it is over year 2078, make it null. It was also advised that check for null before checking date.
I tried doing this,
[Derived Column Name] [Derived Column ] [Expression]
[ MyDate ] [Replace "MyDate"] [MyDate == "" ? NULL(DT_WSTR,5) : MyDate]
[ VerifiedDates ] [Add As New Column] [VerifiedDates == YEAR((DT_DBDATE)MyDate) > = 2078 ? NULL(DT_WSTR,10) : MyDate]
But this did not work for two reasons. Not only was the expression wrong, it also would not allow me to replace the column of "MyDate" like I did in the first run. Can I not replace a column more than once? Do these tasks happen at the same time?
Due to that issue, I tried to just replace the dates via the expression
[ MyDate ][Replace "MyDate"][YEAR((DT_DBDATE)MyDate) >= 2078 ? NULL(DT_WSTR, 10) : MyDate]
as well as
[ MyDate ][Replace "MyDate"][MyDate == YEAR((DT_DBDATE)MyDate) >= 2078 ? NULL(DT_WSTR, 10) : MyDate]
But none of these seem to be the correct syntax... Can anyone point me to where I am off?
I'm also having trouble finding a good resource for the syntax, presently using this ref
Have you tried the DATEPART function instead
[ MyDate ][Replace "MyDate"][ DATEPART("yyyy", (DT_DBTIMESTAMP)MyDate) >= 2078 ? NULL(DT_WSTR, 10) : MyDate ]
Here is the code snippet I am trying to get to work:
final Query query = pm.newQuery("SELECT FROM model.Strip WHERE publishOn <= startDate
&& endDate >= publishOn PARAMETERS Date startDate, Date endDate import java.util.Date");
Since I am only querying on a single parameter, this should work according to the Google Docs.
Inequality Filters Are Allowed on One
Property Only A query may only use
inequality filters (<, <=, >=, >, !=)
on one property across all of its
filters. For example, this query is
allowed:
import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.datastore.Query.FilterOperator;
import com.google.appengine.api.datastore.Query.SortDirection;
Query q = new Query("Person");
q.addFilter("birthYear", FilterOperator.GREATER_THAN_OR_EQUAL, minBirthYearParam);
q.addFilter("birthYear", FilterOperator.LESS_THAN_OR_EQUAL, maxBirthYearParam);
of course that is using the low-level Datastore interface, but I would expect that the JDO implementation just uses that as well.
But I am getting this un-helpful error message when I run my query.
org.datanucleus.store.appengine.query.DatastoreQuery$UnsupportedDatastoreFeatureException:
Problem with query = publishOn
PARAMETERS Date startDate, Date
endDate import java.util.Date>:
Unexpected expression type while
parsing query:
org.datanucleus.query.expression.ParameterExpression
Does anyone know how to do a ranged query like this
I figured it out . . .
final Query query = pm.newQuery("SELECT FROM model.Strip WHERE publishOn <= startDate
&& endDate >= publishOn PARAMETERS Date startDate, Date endDate import java.util.Date");
changed to
final Query query = pm.newQuery("SELECT FROM model.Strip WHERE this.publishOn >= startDate
&& this.publishOn <= endDate PARAMETERS java.util.Date startDate, java.util.Date endDate");
you have to put the property before the variable, the this. doesn't hurt either
I switched to Objectify so I would have to fight these stupid JDO/JPAsemantics!