Skip to main content

OData Data Types

About Data Types

A little cheat sheet regarding OData's data types:

OData TypeVersionJS formatExample
Edm.StringV2 & V4string"Test"
Edm.BooleanV2 & V4booleantrue
Edm.Int16V2 & V4number3
Edm.Int32V2 & V4number222
Edm.ByteV2string"1"
Edm.ByteV4number1
Edm.SByteV2string
Edm.SByteV4number
Edm.Int64V2string
Edm.Int64V4number
Edm.SingleV2string
Edm.SingleV4number
Edm.DoubleV2string
Edm.DoubleV4number
Edm.DecimalV2string
Edm.DecimalV4number
Edm.DurationV4string"P12DT12H15M"
Edm.TimeV2string"PT12H15M"
Edm.TimeOfDayV4string"12:15:00"
Edm.DateV4string"2022-12-31"
Edm.DateTimeV2string"/Date(123...)/"
Edm.DateTimeOffsetV2 & V4string"2022-12-31T12:15:00+01:00"
Edm.BinaryV2 & V4string
Edm.StreamV4---streams are accessed differently and thus are out of scope

V4 Data Types

OData V4 TypeDescriptionURL formatURL ExampleJSON type
Edm.Booleanboolean valueliteraltrue
false
boolean
Edm.Stringstring valuequoted'Some Test'string
Edm.Byteunsigned 8-bit integer valueliteral1number
Edm.SBytesigned 8-bit integer valueliteral-1number
Edm.Int16signed 16-bit integer valueliteral123number
Edm.Int32signed 32-bit integer valueliteral123number
Edm.Int64signed 64-bit integer valueliteral123number
Edm.Singlefloating point number with 7 digits precisionliteral1.1number
Edm.Doublefloating point number with 15 digits precisionliteral1.2number
Edm.Decimalnumeric values with arbitrary precision and scaleliteral12.22number
Edm.Guid16-byte (128-bit) unique identifier valueliteral...string
Edm.DurationdurationliteralPT12H59M10S
P1Y
PT12.123S
string
Edm.TimeOfDayspecific time of dayliteral12:59:10
12:15
12:15:03.123
string
Edm.Datespecific dayliteral2022-12-31string
Edm.DateTimeOffsetspecific point in timeliteral2022-12-31T23:59:59Z
2022-12-31T23:59:59+02:00
string
Edm.Binaryfixed or variable length binary database64 encoded string
Edm.Streammost filter operations don't work here
also exclusive handling
Edm.Geography.*
Edm.Geometry.*

V2 Data Types

The special thing about V2 OData services is, that we have to differentiate between using OData types in the URL or in JSON, since they are formatted differently:

  • URL: values in filter queries ($filter) or function parameters (which are query parameters)
  • JSON: values in request or response bodies

The following table lists information about all V2 data types according to the official resources used.

For URL usage, see chapter 6 "Primitive Data Types" of the V2 overview document. This is the most authoritative resource despite it's lack of being a true specification.

For JSON usage, see chapter 4 "Primitive Types" of the document about the V2 JSON format.

OData V2 TypeDescriptionURL formatURL exampleJSON typeJSON example
Edm.Booleanboolean valueliteraltruebooleantrue
Edm.Stringstring valuequoted'test'string"test"
Edm.Byteunsigned 8-bit integer valueliteral1string"1"
Edm.SBytesigned 8-bit integer valueliteral-1string"-1"
Edm.Int16signed 16-bit integer valueliteral123number123
Edm.Int32signed 32-bit integer valueliteral123number123
Edm.Int64signed 64-bit integer valuetype suffix "L"123Lstring"123"
Edm.Singlefloating point number with 7 digits precisiontype suffix "f"1.1fstring"1.1"
Edm.Doublefloating point number with 15 digits precisiontype suffix "d"1.2dstring"1.2"
Edm.Decimalnumeric values with arbitrary precision and scaletype suffix "M" or "m"12.22Mstring"12.22
Edm.Guid16-byte (128-bit) unique identifier valuetype prefix "guid"guid'xxx...'string"xxx..."
Edm.Timeday time duration representing time of daytype prefix "time"time'PT12H59M10S'string"PT12H59M10S"
Edm.DateTimespecific point in timetype prefix "datetime"datetime'2022-12-31T23:59:59'string"/Date(123...)/"
Edm.DateTimeOffsetspecific point in timetype prefix "datetimeoffset"datetimeoffset'2022-12-31T23:59:59Z'string"2022-12-31T23:59:59+01:00"
Edm.Binaryfixed or variable length binary datatype prefix "X" or "binary"binary'23A'base64 encoded string"..."

Edm.DateTime is quite special in multiple ways:

  1. URL and JSON representation are completely different
  2. the JSON representation has quite a unique format
  3. Edm.DateTime is not really consistent with Edm.DateTimeOffset

Another oddity is Edm.Time, since it is defined as duration (by the way, the static "P" stands for "period"). Now the "spec" states, that it should represent a specific time of day and refers to the "day time duration" as definition.

I think that the definition is flawed for two reasons. First, "day time duration" also allows for specifying a period of days, which doesn't overlap with time of day. Second, a duration might be able to represent a time of day, in the sense that a duration of 6 hours and 12 minutes might also represent "06:12", but both data types usually have different restrictions. Time of day requires the specification of hours and minutes, while duration might specify any of its parts, e.g. only seconds "PT12S".