Kjeld
Kjeld

Reputation: 470

How to cast a property of type Edm.String to numeric in Odata V2

I am querying a Odata V2 service. The entity Foo has a property Bar of type Edm.String . Bar is a time in milliseconds that, sadly, was defined as a string. E.g. "1597091642312".

How can I query Foo for results where Bar is only after a specific point in time?

I tried to cast, like this:

/Bar?$filter=cast(Foo,Edm.Int64) gt 631148400000

But then I get:

Feature is not supported: Expression "5" in $filter or $orderby query options

Especially the '5' does not make sense to me.

The providing service is a SAP CAP CDS mock service, using a V4 to V2 proxy.

Upvotes: 0

Views: 1788

Answers (1)

Kjeld
Kjeld

Reputation: 470

Ok so it seems that you can do this:

/Bar?$filter=Foo gt '631148400000'

And no cast should be necessary. I assume the gt is applied alphanumerically, which has the same effect if it were applied numerically?

However, when using the timestamp 631148400000 I get no results (which pushed me in the direction of String being a problem). I do get results with a more recent timestamp (in 2019 or 2020).

I am not sure if this is a Odata V2 problem, or a problem with my SAP CDS mock service.

Upvotes: 0

Related Questions