Skip to content

SDMX Data Queries: HowTo

Attilio Mattiocco edited this page Sep 29, 2022 · 18 revisions
  1. Creating data constraints
  2. Special keys
  3. Adding time constraints
  4. Useful Links

Creating data constraints

A data query is a sequence of tokens that uniquely identifies the resource in the SDMX provider. We'll refer to this sequence as the SDMX identifier of the resource. The identifier depends on the structure (DSD) of the dataflow that contains the resource.

Let's use the EXR dataflow from ECB as an example. The DSD for this dataflow declares 5 dimensions:

  1. FREQ
  2. CURRENCY
  3. CURRENCY_DENOM
  4. EXR_TYPE
  5. EXR_SUFFIX

This means that, in order to uniquely identify a resource in this dataflow, the identifier will have to contain the name of the dataflow plus 5 tokens representing the dimensions (you can think of the dataflow as a DB table whos primary key is made of 5 columns).

The tokens that have to be used to identify dimension values are the codes declared in the codelist associated to every single dimension. Take the FREQ dimension as an example: the codelist for it is the CL_FREQ.

So, if we want to retrieve a time series from the EXR dataflow, we'll have to build a resource identifier that is made of 6 tokens: one representing the flow (always the first) and the others representing legal values for each dimension, in the very same order as they are declared in the DSD of the flow

An example is EXR/A.USD.EUR.SP00.A, that means:

  • EXR: the flow
  • A: code for FREQ dimension
  • USD: code for CURRENCY dimension
  • EUR: code for CURRENCY_DENOM dimension
  • SP00: code for EXR_TYPE dimension
  • A: code for EXR_SUFFIX dimension

NOTE: not every combination of legal dimension codes is actually associated to a resource. Some combinations, though valid, produce no results (or, in 2.1 providers, they return an HTTP 404 error code).

Special keys

Two special keys are supported in data queries:

  1. The wildcard (an empty character) means all the available codes
  2. The '+' means a logic OR and can be used to query multiple codes.

Examples of usage for this characters:

EXR/.USD.EUR.SP00.A queries all available frequencies

EXR/A+M.USD.EUR.SP00.A queries Annual and Monthly frequencies

Multiple requests

You can query multiple time series (also from different data flows) in a single request by means of the ';' separator. As an example the query

EXR/A.USD.EUR.SP00.A;EXR/A.GBP.EUR.SP00.A;EXR/M.USD.EUR.SP00.A

will return 3 time series.

This method is less efficient, as it performs multiple separate requests, but it has the advantage to respect the request order in the output.

Adding time constraints

The time constraints can be added in various formats. Following you can check some of them.

# select years
getTimeSeries('ECB', 'EXR/D.USD.EUR.SP00.A', '2000', '2001')
# select months
getTimeSeries('ECB', 'EXR/D.USD.EUR.SP00.A', '2000-01', '2000-12')
# select quarters
getTimeSeries('ECB', 'EXR/D.USD.EUR.SP00.A', '2000-Q1', '2000-Q2')
# select days
getTimeSeries('ECB', 'EXR/D.USD.EUR.SP00.A', '2000-01-01', '2000-01-31')

Useful Links