Bulk functions in the Inflector DuckDB extension
Sample data for the examples
Each browser example starts with these sample tables; sample files are shared across examples on this page. Run this setup first when trying the examples in your own DuckDB session.
-- Fixtures for inflector cookbook / technical-details / functions.json examples.
-- Small, deterministic, idempotent. Backs snippets that read from
-- `api_events` (struct payload), `models` (class names), `mixed_input`
-- (raw case-mixed strings), and `left_records` / `right_records` (dedupe pair).
CREATE OR REPLACE TABLE api_events (
id INTEGER,
payload STRUCT(firstName TEXT, lastName TEXT)
);
INSERT INTO api_events VALUES
(1, {'firstName': 'John', 'lastName': 'Doe'}),
(2, {'firstName': 'Jane', 'lastName': 'Roe'}),
(3, {'firstName': 'Mary', 'lastName': 'Sue'});
CREATE OR REPLACE TABLE models (
class_name TEXT
);
INSERT INTO models VALUES
('UserAccount'),
('Message'),
('Order');
CREATE OR REPLACE TABLE mixed_input (
raw TEXT
);
INSERT INTO mixed_input VALUES
('helloWorld'),
('HelloWorld'),
('hello_world'),
('hello-world');
CREATE OR REPLACE TABLE left_records (
id INTEGER,
name TEXT
);
INSERT INTO left_records VALUES
(1, 'helloWorld'),
(2, 'fooBar');
CREATE OR REPLACE TABLE right_records (
id INTEGER,
name TEXT
);
INSERT INTO right_records VALUES
(10, 'hello_world'),
(20, 'foo_bar');
-- Small files for the file-ingestion examples, in the browser's filesystem.
COPY (SELECT 'Ada' AS firstName, 'Lovelace' AS lastName, '[email protected]' AS emailAddress)
TO 'users.csv' (HEADER true);
COPY (SELECT 'Ada' AS firstName, 'Lovelace' AS lastName)
TO 'data.csv' (HEADER true);
COPY (SELECT 'Ada' AS firstName, 'Lovelace' AS lastName)
TO 'events.json' (FORMAT JSON, ARRAY true);
Function category
Bulk
1 functionApply a transform to every key in a struct or every column name in a query result, in a single call. The headline feature for normalizing API responses or migrating between naming conventions.
Signature
5 overloaded forms · click to inspectArguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
format
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
text
|
Type
VARCHAR
|
Mode Positional | Description |
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
format
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
value
|
Type
ANY
|
Mode Positional | Description |
Arguments
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
format
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
query
|
Type
TABLE
|
Mode Positional | Description |
Argument
strip_accents
|
Type
BOOLEAN
|
Mode Named | Description |
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
format
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
text
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
strip_accents
|
Type
BOOLEAN
|
Mode Positional | Description |
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
format
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
value
|
Type
ANY
|
Mode Positional | Description |
Argument
strip_accents
|
Type
BOOLEAN
|
Mode Positional | Description |
Description
Apply a named transform ('camel', 'snake', 'pascal', 'kebab', etc.) to one of: a string, every key in a struct, or every column name in a query result. The headline function for renaming a whole shape in one call. Pass strip_accents := true to the table form, or true as a third argument to the scalar form, to remove diacritics from the transformed names ('CaféNoël' → 'cafe_noel'). In the DuckDB 2.0 build, names that collide after renaming (for example fooBar and foo_bar both becoming foo_bar) are made unique in column order by appending _1, _2, …, compared case-insensitively like DuckDB identifiers; earlier builds produced duplicate column names.
SELECT inflect('snake', {'firstName':'John','lastName':'Doe'});
SELECT * FROM inflect('kebab', (FROM read_csv('data.csv')));
SELECT inflect('snake', 'CaféNoël', true);
SELECT * FROM inflect('snake', (SELECT 1 AS fooBar, 2 AS foo_bar));