ANSI X12 / UN-EDIFACT EDI in SQL — sniff transaction type, read the interchange delimiter set, count segments, extract segment data elements
Maintainer(s):
alitrack
Compatibility Matrix
This table covers all DuckDB releases that have not reached end-of-life, including LTS releases, and shows the 2 most recent patch releases of each. Older patch releases are not listed, but the extension may be available for them as well.
| Platform | 1.4.4 | 1.4.5 | 1.5.5 | 1.5.6 | 2.0.0 |
|---|---|---|---|---|---|
| Linux AMD64 | |||||
| Linux ARM64 | |||||
| macOS AMD64 | |||||
| macOS ARM64 | |||||
| Windows AMD64 | |||||
| Windows ARM64 | |||||
| WebAssembly |
Installing and Loading
INSTALL x12 FROM community;
LOAD x12;
Example
INSTALL x12 FROM community;
LOAD x12;
-- Transaction type (ST01 for X12, UNH02 for EDIFACT), NULL if not EDI
SELECT x12_transaction_type('ISA*00* *00* *ZZ*S*ZZ*R*240101*1200*U*00401*000000001*0*P*>~ST*835*0001~SE*2*0001~');
-- Sniffed delimiter set + family
SELECT x12_delimiters('ISA*00*00*ZZ*S*ZZ*R*240101*1200*U*00401*1*0*P*>~ST*835*0001~');
-- Segment count, and the Nth segment's data elements
SELECT x12_segment_count('ISA*...~ST*835*0001~SE*2*0001~');
SELECT x12_elements('ISA*...~ST*835*0001~SE*2*0001~', 1);
About x12
x12 — EDI in SQL
Structural ANSI X12 / UN-EDIFACT parser (envelope + segments +
delimiters, serde only, no I/O, no network). Ported from the MIT-licensed
Query-farm vgi-x12 worker.
| Function | Returns | Notes |
|---|---|---|
x12_transaction_type(content) |
VARCHAR | First ST01 / UNH02 code, NULL if not EDI |
x12_delimiters(content) |
STRUCT | Element/segment/component/repetition/release + family |
x12_segment_count(content) |
BIGINT | Body segments (ST..SE) across transactions; -1 when not EDI |
x12_elements(content, n) |
LIST | The Nth segment's data elements (0-based, document order) |
→ GitHub
Added Functions
| function_name | function_type | description | comment | examples |
|---|---|---|---|---|
| x12_delimiters | scalar | NULL | NULL | |
| x12_elements | scalar | NULL | NULL | |
| x12_segment_count | scalar | NULL | NULL | |
| x12_transaction_type | scalar | NULL | NULL |
Overloaded Functions
This extension does not add any function overloads.
Added Types
This extension does not add any types.
Added Settings
| name | description | input_type | scope | aliases | typed_value |
|---|---|---|---|---|---|
| temp_directory | Set the directory to which temporary files are written. | VARCHAR | GLOBAL | [] | post.db.tmp |
© 2026 DuckDB Foundation, Amsterdam NL