I have an azure storage table which Im trying to filter by timestamp. I am using TableClient by @azure/data-tables to achieve this. I used odata query expression to do the filtering.
import { AzureNamedKeyCredential, TableClient } from "@azure/data-tables";
const credential = new AzureNamedKeyCredential("AccountName", "AccountKey");
const tableName = "SomeTable";
const serviceClient = new TableClient( `https://${connectionObject.AccountName}.table.core.windows.net`,
tableName,
credential
);
const page = await serviceClient
.listEntities({
queryOptions: {
// filter: `RowKey ge 'someunixvalue'`, //this works
filter: `timestamp ge datetime'2022-06-27T02:57:35.1831423Z'` //this doesnt work.
}
})
.byPage({ maxPageSize: 1000, continuationToken })
.next();
I have confirmed that the data has a field called timestamp and the value is 2022-06-27T02:57:35.1831423Z for one of the entities. The value of page.value will be an empty array for the failed case whereas the passing case has values.
What am I missing?
Like this, uppercase T, and without a space between single quotes-- it's also highly advisable to use a partitionkey to prevent total table scans, assuming you have more than one partition key (you should):
let ents = client.listEntities({ queryOptions: {
partitionKey: key_name,
filter: "Timestamp lt datetime'2023-03-25T21:02:43.8445081Z'"
}})