Systems Integration

Query Languages

Prof. Dr. Christian Drumm

04.11.2026

Overview

Query Languages

Extracting data from databases, XML documents, and JSON

  • Query languages allow systems to retrieve, filter, and combine data
  • Three widely used languages are covered in this lecture:
    • SQL — the standard language for relational databases
    • XPath — the standard language for navigating XML documents
    • jq — a widely used filter language for JSON
  • All are declarative: they describe what data is needed, not how to retrieve it
  • All operate on the syntactic level of interoperability

XPath is also the basis for XSLT, one of the transformation languages discussed in the next lecture.

Learning Objectives

After this lecture, you should be able to:

  • Explain the four functional categories of SQL
  • Write basic DDL, DQL, DML, and DCL statements
  • Describe the evolution of the SQL standard
  • Navigate XML documents with XPath path expressions
  • Solve practical XPath queries on an XML document
  • Query JSON with jq filters

SQL vs. XPath vs. jq

Three languages, three data models

Aspect SQL XPath jq
Data model Relational tables XML node tree JSON
Standard ISO/IEC 9075 W3C XPath not standardized
Core concept Rows and columns Nodes and paths Filters and pipes
Filtering WHERE clause Predicates [...] select(...)
Aggregation COUNT, SUM, AVG, … count(), sum(), … length, add, …
Integration Data extraction, ETL, mapping XSLT, XQuery, SQL/XML API, log, and ETL pipelines

All three languages are declarative and focus on what data to retrieve.

SQL

SQL — Introduction

Structured Query Language

  • Standard language for managing and interacting with relational databases
  • Provides a robust set of tools for:
    • defining the structure of a database
    • querying and manipulating data
    • controlling access to data
  • SQL is declarative: you specify the result, not the algorithm
  • Standardized by ANSI/ISO since 1986
  • Still the dominant language for relational data management

The relational model and SQL remain the most widely used technologies for managing data today.

SQL — Language Categories

Four functional categories

Category Purpose Key Statements
DDL — Data Definition Language Define and modify database structure CREATE, ALTER, DROP
DQL — Data Query Language Retrieve and query data SELECT
DML — Data Manipulation Language Insert, update, and delete data INSERT, UPDATE, DELETE
DCL — Data Control Language Control access and permissions GRANT, REVOKE

The categories are often summarized as define, query, manipulate, and control.

SQL — Data Definition (DDL)

Data Definition Language

  • Defines and modifies the structure of database objects
    • tables, indexes, views, schemas
  • DDL statements create, alter, or remove objects

Key DDL Statements

  • CREATE — create tables, indexes, views, and databases
  • ALTER — modify existing objects, e.g. add a column or change a data type
  • DROP — remove objects such as tables or indexes

SQL — DDL Example

Creating a table

CREATE TABLE Products (
    id INT PRIMARY KEY,
    name VARCHAR(255),
    price DECIMAL(10, 2),
    stock INT
);
  • id is the primary key — uniquely identifies each product
  • name stores the product name
  • price uses a fixed-point type suitable for monetary values
  • stock stores the available quantity

DDL defines the schema; it does not insert any data.

SQL — Data Querying (DQL)

Data Query Language

  • Deals with retrieving and querying data from the database
  • Primary focus: the SELECT statement
  • Supports:
    • selecting columns and rows
    • sorting and ordering
    • aggregating data
    • joining multiple tables

Example Query

SELECT name, price
FROM Products
WHERE price > 1000;

Retrieves the name and price of all products with a price greater than 1000.

SQL — DQL Key Elements

Clause Purpose
SELECT Defines which columns to retrieve
FROM Specifies the table(s) from which data is pulled
WHERE Applies conditions to filter rows
ORDER BY Sorts the result
JOIN Combines data from multiple tables
GROUP BY Groups rows for aggregation

SELECT and FROM are mandatory; all other clauses are optional.

SQL — Data Manipulation (DML)

Data Manipulation Language

  • Inserts, updates, and deletes data
  • Changes the content of the database without altering its structure


INSERT

INSERT INTO Products
  (id, name, price, stock)
VALUES
  (1, 'Mountain Bike',
   1200.00, 10);

UPDATE

UPDATE Products
SET price = 1300.00
WHERE id = 1;

DELETE

DELETE FROM Products
WHERE id = 1;

SQL — Data Control (DCL)

Data Control Language

  • Controls access to data within the database
  • Manages user permissions and security
  • Key statements:
    • GRANT — grants specific privileges to a user or role
    • REVOKE — removes specific privileges from a user or role

Grant access

GRANT SELECT, INSERT
ON Products
TO user_name;

Revoke access

REVOKE INSERT
ON Products
FROM user_name;

SQL — Versions

A standard that keeps evolving

  • The relational model and SQL are still the most used technologies for data management
  • The historic evolution is discussed in the SIGMOD paper by Stonebraker and Pavlo1
  • The SQL standard evolved significantly over time
Version Year Key Improvements
SQL-86 1986 First formal standard; basic querying and manipulation
SQL-92 1992 Major expansion: data types, joins, set operations, transactions
SQL:2003 2003 XML support, identity columns, MERGE
SQL:2016 2016 JSON support, row pattern recognition, polymorphic table functions

We discuss the versions highlighted in the lecture in more detail on the following slides.

SQL — Adopting Functionality

Why SQL keeps evolving

  • Stonebraker and Pavlo trace the history of database systems1
  • Specialized systems repeatedly emerge:
    • object-oriented
    • XML
    • column-oriented
    • recently AI-focussed
  • Relational databases and SQL endure by adopting their most useful features and functions while maintaining proven core
  • The result is a general-purpose language that keeps expanding

SQL-86 — The First Standard

SQL-1 — 1986

  • The first formal SQL standard, based on IBM’s SQL language
  • Introduced the basic SQL constructs:
    • SELECT, INSERT, UPDATE, DELETE
    • WHERE, FROM
  • Laid the foundation for relational databases
  • Limitations:
    • no integrity constraints
    • no explicit join syntax
    • no transaction control

SQL-86 provided a good foundation, but lacked advanced features needed in enterprise systems.

SQL-92 — A Major Expansion

SQL-2 — 1992

  • Significantly extended SQL with more advanced features
  • Data types: DATE, TIME, TIMESTAMP
  • Joins: outer joins (LEFT, RIGHT, FULL)
  • Set operations: UNION, EXCEPT, INTERSECT
  • Subqueries: correlated subqueries and flexible nesting
  • Transaction control: COMMIT and ROLLBACK
  • String functions: SUBSTRING, POSITION, TRIM
  • Schema management: improved definition of database objects

SQL-92 was widely adopted and set the stage for more advanced SQL functionality.

SQL:2003 — XML

  • XML support — handle XML data natively within SQL databases
    • XMLELEMENT (SQL:2003); XMLQUERY, XMLTABLE (SQL/XML:2006)
  • Auto-increment columns — GENERATED AS IDENTITY
  • MERGE statement — combines INSERT, UPDATE, and DELETE
    • simplifies upsert operations
  • Addressed common enterprise needs:
    • semi-structured data
    • auto-generated keys
    • advanced querying

SQL:2003 brought XML into relational databases and simplified common enterprise tasks.

SQL:2016 — JSON and Advances Queries

  • JSON support — functions for handling JSON data
    • JSON_VALUE
    • JSON_QUERY
    • JSON_TABLE
  • Row pattern recognition — MATCH_RECOGNIZE for sequence matching
  • Polymorphic table functions — result type determined at runtime
  • Formatted date/time and LISTAGG — new formatting and aggregation features

SQL:2016 brought SQL into the modern age of semi-structured data.

SQL — Key Takeaways

  • SQL is the standard language for relational databases
  • The four sub-languages cover definition, querying, manipulation, and control
  • The standard evolved from basic queries to XML, JSON, and advanced query features
  • SQL remains dominant by absorbing features from specialized database systems
  • SQL is a foundation for data extraction, ETL, and mapping in integration scenarios

XPath

XPath — Introduction

XML Path Language

  • Query language for selecting nodes from XML documents
  • Navigates and queries XML data based on its hierarchical structure
  • Powerful tool for locating and extracting specific data elements
  • Often used in conjunction with:
    • XSLT — transformation of XML
    • XQuery — querying XML
    • SQL/XML — combining SQL and XML
  • W3C standard

XPath is the basis for XSLT, which we discuss in the next lecture.

XPath — Running Example

The XML document used throughout this section

<products>
  <product id="1">
    <name>Mountain Bike</name>
    <price currency="USD">1200.00</price>
    <stock>10</stock>
  </product>
  <product id="2">
    <name>Road Bike</name>
    <price currency="USD">900.00</price>
    <stock>5</stock>
  </product>
  <product id="3">
    <name>Helmet</name>
    <price currency="USD">50.00</price>
    <stock>100</stock>
  </product>
  <product id="4">
    <name>Gloves</name>
    <price currency="EUR">25.00</price>
    <stock>50</stock>
  </product>
</products>

XPath — Nodes

The XML document as a node tree

  • XPath operates on the XML node tree
  • Most common node types:
Node Type Example Description
Root node the document itself topmost node of the XML document
Element nodes <product> represent XML elements
Attribute nodes id="1", currency="USD" represent attributes within elements
Text nodes Mountain Bike text content inside elements

A simplified tree

document
└── products
    ├── product[@id="1"]
    │   ├── name   → "Mountain Bike"
    │   ├── price  → "1200.00" [@currency="USD"]
    │   └── stock  → "10"
    └── ...

XPath — Path Expressions

Navigating the document

  • Path expressions select nodes based on their position in the document
  • Two main types:
    • Absolute path — starts at the root node, denoted by /
    • Relative path — starts at the current context node
  • // selects nodes anywhere in the document (all descendants)
Expression Meaning
/products/product all product elements that are children of products
product/name name elements relative to the current product
//name all name elements anywhere in the document
/products//price all price descendants of products

XPath — Predicates

Filtering nodes

  • Predicates filter nodes based on conditions
  • Enclosed in square brackets: [...]
  • Can filter by position, attribute, or content
Predicate Filters by Result
/products/product[1] position first product element
/products/product[@id='2'] attribute value product with id="2"
/products/product[price > 500] element content products with price above 500
/products/product[price/@currency='EUR'] attribute value products priced in EUR
/products/product[stock < 10] element content products with stock below 10

XPath — Axes

Relationships between nodes

  • Axes define the relationship between the current node and other nodes
  • Allow navigation up and down the tree
  • child is the default axis and can be omitted
Axis Selects Example
child all child nodes /products/product/child::name ≡ /products/product/name
parent the parent node /products/product/name/parent::product
descendant all descendants /products/descendant::price
attribute attributes of the current node /products/product/price/attribute::currency

XPath — Functions

Manipulating and evaluating data

  • XPath provides functions to manipulate data and evaluate conditions
  • Common functions:
Function Purpose Example Result
text() returns the text content of a node /products/product[1]/name/text() Mountain Bike
contains() checks whether a string contains a substring /products/product[contains(name, 'Bike')]/name Mountain Bike, Road Bike
count() counts the nodes in a node set count(/products/product) 4

XPath also provides functions for string manipulation, arithmetic, and boolean expressions.

Example 1 — All Product Elements

XPath:

/products/product

Result: all four product elements

id name price stock
1 Mountain Bike 1200.00 USD 10
2 Road Bike 900.00 USD 5
3 Helmet 50.00 USD 100
4 Gloves 25.00 EUR 50

XPath returns the selected nodes; the table shows their content for readability.

Example 2 — Name of the First Product

XPath:

/products/product[1]/name

Result:

<name>Mountain Bike</name>
  • [1] selects the first product element
  • /name then selects its name child
  • The result is a node set with one element node

Example 3 — All Price Elements

XPath:

//price

Result: all price elements anywhere in the document

currency price
USD 1200.00
USD 900.00
USD 50.00
EUR 25.00
  • // searches through all descendants of the context node
  • At the start of an expression, it searches from the root

Example 4 — Attribute Presence

XPath:

/products/product[price/@currency]

Result: all four product elements

id name price
1 Mountain Bike 1200.00 USD
2 Road Bike 900.00 USD
3 Helmet 50.00 USD
4 Gloves 25.00 EUR

The predicate checks only whether the currency attribute exists — not its value. If a price element lacked currency, that product would be omitted.

Example 5 — Currency Attributes

XPath:

/products/product/price/@currency

Result: the currency attribute of all price elements

currency="USD"
currency="USD"
currency="USD"
currency="EUR"
  • The result contains attribute nodes, not element nodes
  • The expression can be shortened using //: //price/@currency

Example 6 — Products with Price Greater than 500

XPath:

/products/product[price > 500]

Result: products 1 and 2

id name price stock
1 Mountain Bike 1200.00 USD 10
2 Road Bike 900.00 USD 5
  • The predicate compares the numeric value of the price element
  • Products with a price of 500 or less are filtered out

Example 7 — Products Priced in EUR

XPath:

/products/product[price/@currency='EUR']

Result: product 4

id name price stock
4 Gloves 25.00 EUR 50
  • The predicate filters on the value of the currency attribute
  • This is different from Example 4, which only checks for presence

Example 8 — Counting Products

XPath:

count(/products/product)

Result:

4
  • The count() function returns the number of nodes in a node set
  • The result is a number, not a node set
  • Useful for validation and reporting

Example 9 — Products with Low Stock

XPath:

/products/product[stock < 10]

Result: product 2

id name price stock
2 Road Bike 900.00 USD 5
  • Only the Road Bike has a stock value below 10
  • The Mountain Bike has exactly 10 and is not included

Example 10 — Products Containing “Bike”

XPath:

/products/product[contains(name, 'Bike')]/name

Result:

<name>Mountain Bike</name>
<name>Road Bike</name>
  • contains() checks whether a string contains a substring
  • The predicate filters product elements before /name selects their names
  • Useful for fuzzy matching in XML data

XPath — Exercise

Writing XPath Expressions

In this exercise, you will write XPath expressions to query an XML document representing a list of products.

  • Use the XML document on the following slides
  • Write expressions for the seven queries
  • Check your results with an XPath evaluator, e.g. codebeautify.org/Xpath-Tester
  • Use the XML document from the lecture notes as a basis

Work in pairs and compare your expressions.

Exercise — Questions 1–4

  1. Select the names of all products
  2. Select the names of all products in the “Accessories” category
  3. Select all product elements that are featured
  4. Count the number of products in the “Outdoor” category


Start with simple path expressions and add predicates where needed.

Exercise — Questions 5–7

  1. Select the names of all products with a price greater than 800
  2. Select all products where the featured element exists
    • regardless of whether its value is true or false
  3. Select all products where the stock is less than 10


Question 6 is about presence, not about the value of the element.

XPath — Key Takeaways

  • XPath selects nodes from XML documents using path expressions
  • / selects from the root; // searches anywhere in the document
  • Predicates filter nodes by position, attribute, or content
  • Axes navigate relationships between nodes
  • Functions such as text(), contains(), and count() extend queries
  • XPath is the foundation for XSLT and XQuery

jq

jq — Introduction

Querying and transforming JSON

  • jq is a command-line processor and query language for JSON
  • A jq program is a filter: it reads JSON and produces a stream of JSON values
  • Filters can select, filter, reshape, aggregate, and format data
  • Common uses: API responses, log processing, and ETL pipelines

jq is the most widely used command-line tool for JSON processing.

jq — Running Example

Same products, JSON data model

{
  "products": [
    {
      "id": 1,
      "name": "Mountain Bike",
      "price": { "amount": 1200.0, "currency": "USD" },
      "stock": 10
    },
    {
      "id": 2,
      "name": "Road Bike",
      "price": { "amount": 900.0, "currency": "USD" },
      "stock": 5
    },
    {
      "id": 3,
      "name": "Helmet",
      "price": { "amount": 50.0, "currency": "USD" },
      "stock": 100
    },
    {
      "id": 4,
      "name": "Gloves",
      "price": { "amount": 25.0, "currency": "EUR" },
      "stock": 50
    }
  ]
}

The nested price object mirrors the XPath price/@currency attribute.

jq — Key Concepts (1/2)

Filters, fields, and pipes

  • Every jq program is a filter; . is the identity filter
  • Field access and iteration:
    • .products — the products array
    • .products[0] — first product
    • .products[] — each product separately
    • .products[].price.amount — chained field access
  • Pipes compose filters: .products[] | .name
  • ? suppresses errors, e.g. .products[].tags[]?

jq — Key Concepts (2/2)

Filtering, construction, functions, and output

  • select(condition) keeps inputs where the condition is true
  • [...] collects a stream into an array
  • {...} builds an object; {name} is shorthand for {name: .name}
  • Common built-ins: length, map, sort_by, group_by, add, contains, has
  • Output options: -c compact, -r raw strings, @csv and @tsv

Typical filters:

  • .products[] | select(.price.amount > 500) — products above 500
  • [.products[] | select(...)] — matches collected into an array
  • {name, price: .price.amount} — a new object
  • .products | length — number of products

jq — Examples: Selection

Examples 1–3

# Filter Result
1 .products all four product objects
2 .products[0].name "Mountain Bike"
3 .products[].price.amount 1200.00, 900.00, 50.00, 25.00
  • .[] emits each element separately
  • Wrap a filter in [...] to collect values into an array

Results are shown as produced by jq -c

jq — Examples: Filtering

Examples 4–7

  • Example 4
    • .products[] | select(.price | has("currency")) | .name
    • all four names
  • Example 5
    • .products[].price.currency
    • "USD", "USD", "USD", "EUR"
  • Example 6
    • [.products[] | select(.price.amount > 500)]
    • Mountain Bike, Road Bike
  • Example 7
    • .products[] | select(.price.currency == "EUR")
    • Gloves

has("currency") checks presence, not the value. This mirrors XPath price/@currency.

jq — Examples: Counting and Strings

Examples 8–10

  • Example 8
    • .products | length
    • 4
  • Example 9
    • .products[] | select(.stock < 10)
    • Road Bike
  • Example 10
    • .products[] | select(.name | contains("Bike")) | .name
    • Mountain Bike, Road Bike

contains("Bike") is a case-sensitive substring test

jq — Exercise

Writing jq Filters

In this exercise, you will write jq filters to query a JSON document representing a list of products.

  • Use the JSON document on the following slides
  • Write filters for the seven queries
  • Check your results with jq play or locally: jq '<filter>' exercise.json

The JSON document mirrors the XML document from the XPath exercise.

jq — Exercise JSON

{
  "store": {
    "products": [
      {
        "id": 1,
        "name": "Mountain Bike",
        "category": "Outdoor",
        "price": { "amount": 1200.0, "currency": "USD" },
        "stock": 10,
        "featured": true
      },
      {
        "id": 2,
        "name": "Road Bike",
        "category": "Outdoor",
        "price": { "amount": 900.0, "currency": "USD" },
        "stock": 5,
        "featured": false
      },
      {
        "id": 3,
        "name": "Helmet",
        "category": "Accessories",
        "price": { "amount": 50.0, "currency": "USD" },
        "stock": 100
      },
      {
        "id": 4,
        "name": "Gloves",
        "category": "Accessories",
        "price": { "amount": 25.0, "currency": "EUR" },
        "stock": 50
      },
      {
        "id": 5,
        "name": "Electric Scooter",
        "category": "Urban Mobility",
        "price": { "amount": 850.0, "currency": "USD" },
        "stock": 20
      }
    ]
  }
}

jq — Exercise Questions

  1. Select the names of all products
  2. Select the names of all products in the “Accessories” category
  3. Select all products that are featured
  4. Count the number of products in the “Outdoor” category
  5. Select the names of all products with a price greater than 800
  6. Select all products where the featured key exists (regardless of whether its value is true or false)
  7. Select all products where the stock is less than 10

jq — Key Takeaways

  • JSON has no single dominant query standard; jq is not standardized but widely supported
  • jq is a filter language for JSON
    • Pipes compose filters; select() filters values
    • [...] and {...} reshape data into arrays and objects
    • Built-ins such as length, sort_by, group_by, add, and contains cover common tasks

Summary

Summary

  • SQL is the standard language for relational databases
    • DDL, DQL, DML, and DCL cover different aspects of data management
    • The standard evolved from SQL-86 to SQL:2016 with XML, JSON, and new query features
  • XPath is the standard language for navigating XML documents
    • Path expressions, predicates, axes, and functions are the core concepts
  • jq is a widely used filter language for JSON
    • Filters, pipes, select(), and built-ins such as length and sort_by
  • All three languages are declarative and essential for data access in integration scenarios
  • The next lecture introduces mapping languages such as XSLT

Why are query languages important for systems integration?

When would you use SQL, XPath, or jq?

References