CAN/CSA-ISO/IEC TR 19075-5-18 — Row Pattern Recognition in SQL: A Comprehensive Technical Guide

Canadian adoption of the ISO/IEC Technical Report on SQL row pattern matching capabilities

Scope and Purpose of CAN/CSA-ISO/IEC TR 19075-5-18

CAN/CSA-ISO/IEC TR 19075-5-18 is the Canadian adoption of the international technical report ISO/IEC TR 19075-5:2016, titled “Information technology — Database languages — SQL technical reports — Part 5: Row pattern recognition in SQL”. Published by the Canadian Standards Association (CSA Group) in 2018, this document provides an in-depth technical overview of the row pattern recognition capabilities added to the SQL language. It is intended for database implementers, application developers, and data analysts who need to understand, design, or evaluate SQL-based pattern matching features, particularly the MATCH_RECOGNIZE clause.

As a Technical Report (TR) rather than a full International Standard, it serves as an informative guide that explains the syntax, semantics, and design rationales behind row pattern recognition. It does not itself define normative requirements but illuminates the technical foundations that later became part of the SQL:2016 standard (ISO/IEC 9075:2016) and its subsequent editions. The Canadian adoption ensures that stakeholders in Canada can reference a locally authored document aligned with international practice.

Note: The designation “-18” in the standard number signifies the year of Canadian adoption (2018), while the base ISO/IEC TR 19075-5 was published in 2016.

Technical Requirements and Core Concepts

Row Pattern Recognition in SQL

The central concept covered in CAN/CSA-ISO/IEC TR 19075-5-18 is order-sensitive row pattern matching — the ability to detect sequences of rows that match a specified pattern within a result set. This is accomplished primarily through the MATCH_RECOGNIZE clause, which can be used in a FROM clause to transform a base table or view into a pattern-annotated relational expression.

Key Elements of the Pattern Matching Model

  • Partitioning and Ordering: Data is divided into partitions by the PARTITION BY clause and ordered within each partition using the ORDER BY clause.
  • Pattern Definition: The PATTERN clause specifies a regular expression-like sequence of row pattern variables (e.g., PATTERN ( A B+ C )), with quantifiers, alternation, grouping, and optional start/end anchors.
  • Row Pattern Variables: Each pattern variable corresponds to a class of rows defined by a condition in the DEFINE clause. These conditions are boolean predicates evaluated against the current row and, optionally, preceding or following rows.
  • Measures and Output: The MEASURES clause computes expressions (e.g., aggregate, positional, or conditional) over matched rows, with the ability to reference row pattern variables and their attributes.
  • Result Row Modes: The ONE ROW PER MATCH, ALL ROWS PER MATCH, and other modes control how the matched subsequence is reflected in the output.

Sample Pattern Matching Scenario

Consider a table of stock trades with columns timestamp, symbol, and price. The following query identifies occurrences of a “head-and-shoulders” pattern:

SELECT * FROM trades MATCH_RECOGNIZE ( PARTITION BY symbol ORDER BY timestamp MEASURES MATCH_NUMBER() AS match_num, RUNNING COUNT(up.total) AS up_count ONE ROW PER MATCH PATTERN (up peak down peak2 down2) DEFINE up AS price > PREV(price), peak AS price > PREV(price) AND price > LAG(price, 2), down AS price < PREV(price), peak2 AS price > PREV(price) AND price > LAG(price, 2), down2 AS price < PREV(price) );
Example Output for Pattern Match (ONE ROW PER MATCH)
symbol match_num up_count start_ts end_ts
AAPL 1 2 2025-04-10 09:31 2025-04-10 15:45
GOOG 1 1 2025-04-11 09:30 2025-04-11 14:20
Tip: Row pattern recognition excels in detecting trends, sequences, and anomalies in ordered data. It is especially powerful for financial analysis, sensor data, and log monitoring.

Implementation Highlights for Database Systems

CAN/CSA-ISO/IEC TR 19075-5-18 discusses several implementation considerations that database vendors and advanced users should be aware of:

  • Efficient Pattern Matching Engine: The TR describes a non‑deterministic finite automaton (NFA) approach to matching, which allows for greedy and reluctant quantifiers. Implementations must carefully manage state space to avoid exponential blow‑up in complex patterns.
  • Support for Empty Matches and Zero‑Length Patterns: The report formally defines behavior for empty matches, which must be handled to prevent infinite loops and ensure predictable results.
  • Integration with SQL’s Streaming Extensions: Although MATCH_RECOGNIZE is defined for static tables, the report outlines how the same semantics can be applied to streaming data, forming the basis for the MATCH_RECOGNIZE clause in SQL streaming standards (e.g., ANSI SQL 2016 for streams).
  • Row Pattern Navigation: Functions like PREV(), NEXT(), FIRST(), and LAST() are defined to navigate within the matched sequence, with specific rules for their behavior when pattern variables span multiple rows.
Caution: Not all database systems implement row pattern recognition identically. The TR provides guidance, but vendors may deviate in quantifier semantics, support for nested patterns, or available navigational functions. Always check the specific implementation documentation.

Compliance, Testing, and Conformance Notes

Because CAN/CSA-ISO/IEC TR 19075-5-18 is a Technical Report, it does not impose formal conformance requirements. However, it serves as an essential reference for evaluating whether a database system correctly implements the MATCH_RECOGNIZE feature as specified in ISO/IEC 9075 (SQL standard). Adopting organizations in Canada may use this report to:

  • Assess Feature Coverage: Compare a product’s implementation against the descriptions in the TR to identify missing or incorrectly implemented capabilities.
  • Develop Test Suites: Use the examples and edge‑case descriptions in the report to design conformance tests for pattern matching.
  • Guide Procurement: Reference the TR when specifying required SQL pattern-matching support in request‑for‑proposal documents.
Conformance Note: As of SQL:2016, full conformance includes the row pattern recognition feature (T131). A database that claims F121 (SQL/JSON) does not automatically support pattern matching. Verify that the product explicitly claims the feature or implements MATCH_RECOGNIZE as described in this TR.
Important: The adoption year (2018) does not reflect the latest changes in the SQL standard. The technical content of ISO/IEC TR 19075-5:2016 remains valid, but newer editions of the SQL standard (e.g., 2016 with corrigenda or 2023) may include updates or clarifications. Always refer to the latest published version of the base standard and the current Canadian adoption notice.

Frequently Asked Questions

Q: Is CAN/CSA-ISO/IEC TR 19075-5-18 a mandatory standard for SQL implementations?
A: No. It is a Technical Report (TR) and is informative rather than normative. It explains the design of row pattern recognition and provides guidance, but it does not set binding requirements. Database vendors may choose to implement the feature as described, but conformance to the SQL standard is governed by the main parts of ISO/IEC 9075.
Q: What is the relationship between this TR and the MATCH_RECOGNIZE clause in SQL?
A: The technical report provides the detailed technical foundation for the MATCH_RECOGNIZE clause that was first standardized in SQL:2016. It explains the syntax, semantics, and design choices, making it an invaluable companion document for implementers and advanced users.
Q: Can I use row pattern recognition in streaming databases?
A: Yes. The semantics described in the TR are designed to be applicable to both static tables and streaming data. Many streaming SQL engines (e.g., Apache Flink, Kafka Streams) implement MATCH_RECOGNIZE based on the same principles. However, streaming environments add considerations around time‑based order and watermarking that are beyond the scope of this report.
Q: Where can I obtain an official copy of CAN/CSA-ISO/IEC TR 19075-5-18?
A: Authorized copies are available from the CSA Group (www.csagroup.org) and through national standards repositories. The original ISO/IEC TR 19075-5:2016 can be purchased from ISO’s member bodies and licensed distributors.


Document prepared for informational purposes. Refer to the official publication of CAN/CSA-ISO/IEC TR 19075-5-18 for the complete authoritative text. Year of adoption: 2026.

📥 Standard Documents Download

🔒
Please wait 10 seconds, the download links will appear after the ad loads

Leave a Reply

Your email address will not be published. Required fields are marked *