DuckDB Extension
Inflector
Convert string case and inflect English words in DuckDB SQL. Rename struct fields, change camelCase to snake_case, or pluralize labels.
On this page
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);
Make names consistent across datasets
Inflector converts strings between conventions such as snake_case, camelCase, and PascalCase. It also provides English pluralization and singularization, plus helpers for rewriting struct keys and result-column names.
Use it when incoming data uses different naming conventions or when an export must match another system’s field names. These are mechanical transformations: they can standardize spelling conventions, but they do not decide whether two differently named fields mean the same thing.
Example
Convert names to snake_case
Apply the same naming convention to two sample field names.
Tested with DuckDB 1.5.6. Browser examples use Haybarn-Wasm 2.0.0-rc12.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL inflector FROM query_farm;
LOAD inflector FROM query_farm;
WITH fields(name) AS (VALUES ('firstName'), ('PostalCode'))
SELECT name, inflector_to_snake_case(name) AS snake_case
FROM fields
ORDER BY name;
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://haybarn-extensions.query.farm';
INSTALL inflector FROM query_farm;
LOAD inflector FROM query_farm;
WITH fields(name) AS (VALUES ('firstName'), ('PostalCode'))
SELECT name, inflector_to_snake_case(name) AS snake_case
FROM fields
ORDER BY name;
INSTALL inflector FROM community;
LOAD inflector;
WITH fields(name) AS (VALUES ('firstName'), ('PostalCode'))
SELECT name, inflector_to_snake_case(name) AS snake_case
FROM fields
ORDER BY name;
Expected result
| name | snake_case |
|---|---|
| PostalCode | postal_code |
| firstName | first_name |
Case conversion changes formatting; it does not establish that two names mean the same thing. English pluralization rules are a separate set of functions.
Common tasks
Deep Dive
Technical Details
The one-call rename
The single most useful pattern: take a CSV or JSON file with camelCase headers and snake-case the entire result set in one statement, no per-column boilerplate:
SELECT *FROM inflect('snake', (FROM read_csv('users.csv')));-- firstName,lastName,emailAddress → first_name,last_name,email_addressinflect is polymorphic on its second argument — pass it a VARCHAR, a STRUCT, or a parenthesized query. Same function name, three shapes:
-- 1. A single stringSELECT inflect('snake', 'helloWorld'); -- 'hello_world'-- 2. A struct — every key renamed, values untouchedSELECT inflect('snake', {'firstName':'John','lastName':'Doe'});-- {'first_name': 'John', 'last_name': 'Doe'}-- 3. A query result — every column header renamedSELECT * FROM inflect('kebab', (FROM read_json('events.json')));That’s the headline feature. The rest of the surface is Rails / ActiveSupport-style scalar helpers for individual values.
inflector_to_plural and inflector_to_singular wrap the cruet Rust crate, whose ruleset and irregular-word table are English. They handle English irregulars such as mouse ↔ mice, analysis ↔ analyses, and quiz ↔ quizzes, but they have no awareness of French, German, Spanish, or any other language. Pass non-English input and you’ll get a mechanical English-rule output, silently. For multilingual content, do inflection upstream and store the result.
The v1.5 source fix 8628623 (extension version 2026100701) adds the missing people → person and children → child rules, including compound suffixes (salespeople → salesperson, grandchildren → grandchild). These suffixes preserve lowercase, title case, and uppercase. The DuckDB 2.0 builds in the Query.Farm repository include the fix. Community build ac9b69f (DuckDB 1.5) leaves people and children unchanged; older installed binaries may still behave that way.
A handful of edge cases inside English are also worth knowing:
- Modern uncountables —
data,species,series— round-trip irregularly. - Mechanical case tokenization —
inflector_to_snake_case('XMLHttpRequest')yieldsxml_http_request. Right for column work; to keep specific acronyms uppercase in PascalCase, camelCase, Title, Train and Sentence output, use theinflector_acronymssetting.
Case formats supported
Every shape Rails / ActiveSupport ships, plus the obvious extras:
| Format | Example | To-function |
|---|---|---|
camelCase |
helloWorld |
inflector_to_camel_case |
PascalCase / ClassCase |
HelloWorld |
inflector_to_pascal_case / inflector_to_class_case |
snake_case |
hello_world |
inflector_to_snake_case |
kebab-case |
hello-world |
inflector_to_kebab_case |
Train-Case |
Hello-World |
inflector_to_train_case |
SCREAMING_SNAKE_CASE |
HELLO_WORLD |
inflector_to_screamingsnake_case |
Title Case |
Hello World |
inflector_to_title_case |
Sentence case |
Hello world |
inflector_to_sentence_case |
table_case (snake plural) |
user_accounts |
inflector_to_table_case |
Each has a matching inflector_is_* predicate — useful when you need to route a value based on its current shape rather than blindly transform.
Inflection helpers
Beyond pure case work:
-
Pluralize / singularize —
inflector_to_plural,inflector_to_singular. -
Ordinalize —
inflector_ordinalize(1→1st),inflector_deordinalize(1st→1). -
Foreign keys —
inflector_to_foreign_key(Message→message_id). -
Module paths —
inflector_demodulize(ActiveRecord::CoreExtensions::String→String),inflector_deconstantize(Net::HTTP→Net). -
Labels, slugs and class names (DuckDB 2.0 build) —
inflector_humanize(author_id→Author),inflector_parameterize(Crème Brûlée: A Recipe!→creme-brulee-a-recipe),inflector_classify(egg_and_hams→EggAndHam).
These are direct ports of the corresponding ActiveSupport::Inflector methods.
Acronyms
The inflector_acronyms setting lists words that stay uppercase in PascalCase, camelCase (except the first word), Title Case, Train-Case and Sentence case output, and in the matching inflector_is_* predicates. Tokens are trimmed and uppercased; one-character tokens are ignored. snake_case, kebab-case and SCREAMING_SNAKE_CASE output are unaffected.
SET inflector_acronyms = ['HTML', 'API'];SELECT inflector_to_pascal_case('html_api_parser') AS pascal, inflector_to_camel_case('parse_html') AS camel;-- HTMLAPIParser, parseHTMLRESET inflector_acronyms;In the DuckDB 2.0 build the setting is session scoped, like other DuckDB settings: SET affects only the current connection and SET GLOBAL sets the default for new ones. Value transforms read it when the query runs, so a prepared statement uses the value in effect when it is executed. Struct field names and inflect(fmt, TABLE) column names are part of the result type, so they use the value in effect when the query is planned. Earlier builds kept the list in a process-wide variable, so a SET in one connection changed results in every connection and every database in the process.
Changes in the DuckDB 2.0 build
inflector_acronymsis per connection (see Acronyms).- Colliding names are made unique. When
inflectrenames struct fields or query columns and two names become the same (fooBarandfoo_barboth becomefoo_bar), later ones get_1,_2, … in column order, compared case-insensitively like DuckDB identifiers. Earlier builds returned duplicate column names, and the struct form could not build the struct. A name that inflects to an empty string (for example___) keeps its original name. - NULL options.
inflect(fmt, TABLE, strip_accents := NULL)and a NULL format in the table form now raise a clear error. The scalar forms return NULL for NULL arguments, as before. - Errors instead of crashes. Input that is not valid UTF-8 or an internal failure in the Rust layer now raises an error, and strings containing NUL bytes are handled correctly.
- New functions:
inflector_humanize,inflector_parameterize,inflector_classify.
SELECT * FROM inflect('snake', (SELECT 1 AS fooBar, 2 AS foo_bar));-- columns: foo_bar, foo_bar_1Inflector vs RapidFuzz
Both extensions live in the Matching & casing group, but they answer different questions:
- Use Inflector when you know exactly what shape you want (
snake_case,kebab-case, plural, foreign-key) and need to mechanically produce it. Single-input, deterministic output. - Use
rapidfuzzwhen you have two strings and want a similarity score — record linkage, dedupe, spell-check. Fuzzy comparison, not transformation. - Both can coexist — normalize naming with Inflector, then fuzzy-match across normalized values with RapidFuzz.
Source
Inflector is implemented in C++ with a Rust binding (cruet + convert_case) for the actual rule engine. Source at github.com/Query-farm/inflector.
Reference
Extension Contents
Quick reference to all available functions and settings organized by category.
| Name | Type | Description |
|---|---|---|
|
Bulk
Apply 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. |
||
| inflect() | Object type: Scalar function |
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.
|
|
Case Transformation
Convert strings between naming conventions: snake_case, camelCase, PascalCase, kebab-case, Train-Case, SCREAMING_SNAKE_CASE, Title Case, Sentence case. Also raw upper/lower transforms. |
||
| inflector_to_camel_case() | Object type: Scalar function | Convert to camelCase. |
| inflector_to_class_case() | Object type: Scalar function | Convert to ClassCase (PascalCase singular). |
| inflector_to_kebab_case() | Object type: Scalar function | Convert to kebab-case (hyphen-separated). |
| inflector_to_lower_case() | Object type: Scalar function | Lowercase every character. |
| inflector_to_pascal_case() | Object type: Scalar function | Convert to PascalCase. |
| inflector_to_screamingsnake_case() | Object type: Scalar function | Convert to SCREAMING_SNAKE_CASE (caps with underscores). |
| inflector_to_sentence_case() | Object type: Scalar function | Convert to Sentence case — first letter capital, rest lowercase, words space-separated. |
| inflector_to_snake_case() | Object type: Scalar function | Convert to snake_case. |
| inflector_to_title_case() | Object type: Scalar function | Convert to Title Case — every word capitalized, space-separated. |
| inflector_to_train_case() | Object type: Scalar function | Convert to Train-Case (capitalized hyphenated). |
| inflector_to_upper_case() | Object type: Scalar function | Uppercase every character. |
|
Configuration
|
||
| inflector_acronyms | Object type: Setting | List of acronyms preserved as uppercase in case conversions (e.g., HTML, API). |
|
Functions
|
||
| inflector_deconstantize() | Object type: Scalar function | Removes the rightmost segment from a constant expression |
| inflector_demodulize() | Object type: Scalar function | Removes the module part from a fully qualified name |
| inflector_deordinalize() | Object type: Scalar function | Removes the ordinal suffix from a string (1st -> 1) |
| inflector_is_camel_case() | Object type: Scalar function | Returns true if the string is in camelCase format |
| inflector_is_class_case() | Object type: Scalar function | Returns true if the string is in ClassCase (PascalCase) format |
| inflector_is_foreign_key() | Object type: Scalar function | Returns true if the string is in foreign key format (ends with _id) |
| inflector_is_kebab_case() | Object type: Scalar function | Returns true if the string is in kebab-case format |
| inflector_is_pascal_case() | Object type: Scalar function | Returns true if the string is in PascalCase format |
| inflector_is_screamingsnake_case() | Object type: Scalar function | Returns true if the string is in SCREAMING_SNAKE_CASE format |
| inflector_is_sentence_case() | Object type: Scalar function | Returns true if the string is in Sentence case format |
| inflector_is_snake_case() | Object type: Scalar function | Returns true if the string is in snake_case format |
| inflector_is_table_case() | Object type: Scalar function | Returns true if the string is in table_case format (snake_case plural) |
| inflector_is_title_case() | Object type: Scalar function | Returns true if the string is in Title Case format |
| inflector_is_train_case() | Object type: Scalar function | Returns true if the string is in Train-Case format |
| inflector_ordinalize() | Object type: Scalar function | Converts a number string to its ordinal form (1st, 2nd, 3rd, etc.) |
| inflector_to_foreign_key() | Object type: Scalar function | Converts a class name to a foreign key column name |
|
Inflection
English plural / singular conversion. Handles irregulars ( |
||
| inflector_to_plural() | Object type: Scalar function | Pluralize an English word — handles irregulars (person→people, mouse→mice). |
| inflector_to_singular() | Object type: Scalar function | Singularize an English word. |
|
Naming Helpers
Convenience builders for Rails-style naming — table_case, foreign-key generation, ClassCase, module-path conversion, and (DuckDB 2.0 build) human-readable labels, URL slugs and table-to-class names. |
||
| inflector_classify() | Object type: Scalar function |
Turn a table name into a class name, like Rails classify: the last word is singularized and the result is rendered in PascalCase.
|
| inflector_humanize() | Object type: Scalar function |
Turn an identifier into a human-readable label, like Rails humanize: a trailing _id is dropped and the rest is rendered in Sentence case.
|
| inflector_parameterize() | Object type: Scalar function |
Build a URL slug: accents are removed, letters are lowercased, and every run of characters that are not letters or digits becomes a single -, with no leading or trailing dash.
|
| inflector_to_table_case() | Object type: Scalar function | Rails-style 'table_case' — snake_case + plural. |
No extension contents match that search.
API Reference
Function Reference
Configuration
Settings
Configure the inflector extension behavior using these settings.
inflector_acronyms
List of acronyms preserved as uppercase in case conversions (e.g., HTML, API). Session scoped: SET affects only the current connection, SET GLOBAL sets the default
[]
Practical Examples
Cookbook
Real-world recipes and patterns for common use cases.
Quick reference
| Need | Pick |
|---|---|
| Convert one string between cases | inflector_to_<case> or inflect(case_name, value) |
| Rewrite every key in a struct | inflect('snake', struct_col) |
| Rewrite every column of a query | SELECT * FROM inflect('snake', (FROM ...)) |
| Pluralize / singularize an English word | inflector_to_plural / inflector_to_singular |
| Rails-style table name from class name | inflector_to_table_case |
| Class name → foreign-key column | inflector_to_foreign_key |
| Detect what case a string is in | inflector_is_* predicates |
| Number → ordinal label | inflector_ordinalize |
Single-string transforms
SELECT inflector_to_camel_case('hello_world'); -- 'helloWorld'SELECT inflector_to_snake_case('HelloWorld'); -- 'hello_world'SELECT inflector_to_pascal_case('hello_world'); -- 'HelloWorld'SELECT inflector_to_kebab_case('helloWorld'); -- 'hello-world'SELECT inflector_to_train_case('helloWorld'); -- 'Hello-World'SELECT inflector_to_screamingsnake_case('helloWorld'); -- 'HELLO_WORLD'SELECT inflector_to_title_case('hello_world'); -- 'Hello World'SELECT inflector_to_sentence_case('helloWorld'); -- 'Hello world'inflect(case_name, value) is the dispatching equivalent. The case name must be constant for the query:
SELECT inflect('camel', 'hello_world'); -- 'helloWorld'SELECT inflect('snake', column_value)FROM (VALUES ('HelloWorld'), ('UserAccount')) AS inputs(column_value);Pluralize / singularize (English only)
SELECT inflector_to_plural('person'); -- 'people'SELECT inflector_to_plural('child'); -- 'children'SELECT inflector_to_plural('quiz'); -- 'quizzes'SELECT inflector_to_singular('mice'); -- 'mouse'SELECT inflector_to_singular('analyses'); -- 'analysis'These wrap the cruet Rust crate’s English ruleset. Non-English input gets English-rule output, silently — handle multilingual text upstream.
Rewrite struct keys
SELECT inflect('snake', {'firstName':'John','lastName':'Doe'});-- {'first_name': 'John', 'last_name': 'Doe'}SELECT inflect('camel', {'first_name':'John','last_name':'Doe'});-- {'firstName': 'John', 'lastName': 'Doe'}Apply against a struct column to normalize a stored API payload in place:
SELECT id, inflect('snake', payload) AS payload_snakeFROM api_events;Rewrite every column of a query
The killer ETL pattern — normalize the headers of a remote file in one statement:
-- camelCase CSV → snake_case columnsSELECT * FROM inflect('snake', (FROM read_csv('users.csv')));-- Mixed-casing JSON → kebab-case columnsSELECT * FROM inflect('kebab', (FROM read_json('events.json')));Wrap with CREATE TABLE AS to land it in the warehouse with clean names:
CREATE TABLE users ASSELECT * FROM inflect('snake', (FROM read_csv('users.csv')));Add strip_accents := true to fold diacritics out of the new names as well — "Prénom Élève" becomes prenom_eleve instead of prénom_élève:
SELECT * FROM inflect('snake', (SELECT 1 AS "Prénom Élève"), strip_accents := true);The scalar form takes the same switch as a third argument: inflect('snake', 'CaféNoël', true) returns 'cafe_noel'.
Build Rails-style derivations
The classic class ↔ table ↔ foreign-key triangle:
SELECT inflector_to_table_case('UserAccount'); -- 'user_accounts' (table)SELECT inflector_to_class_case('user_accounts'); -- 'UserAccount' (class)SELECT inflector_to_foreign_key('Message'); -- 'message_id' (FK column)Useful when emitting DDL or migration code from a model registry:
SELECT class_name, inflector_to_table_case(class_name) AS table_name, inflector_to_foreign_key(class_name) AS fk_columnFROM models;Detect-then-transform
Use inflector_is_* predicates to route values whose case you don’t trust on the way in:
SELECT raw, CASE WHEN inflector_is_snake_case(raw) THEN raw WHEN inflector_is_camel_case(raw) THEN inflector_to_snake_case(raw) WHEN inflector_is_pascal_case(raw) THEN inflector_to_snake_case(raw) WHEN inflector_is_kebab_case(raw) THEN replace(raw, '-', '_') ELSE inflector_to_snake_case(raw) END AS normalizedFROM mixed_input;Ordinalize numbers
SELECT inflector_ordinalize('1'); -- '1st'SELECT inflector_ordinalize('22'); -- '22nd'SELECT inflector_ordinalize('103'); -- '103rd'SELECT inflector_deordinalize('1st'); -- '1'Useful for report labels: 'Top ' || inflector_ordinalize(rank::VARCHAR) || ' result'.
Strip module / namespace prefixes
SELECT inflector_demodulize('ActiveRecord::CoreExtensions::String'); -- 'String'SELECT inflector_deconstantize('Net::HTTP'); -- 'Net'For working with stack traces or class names imported from systems that use Ruby- or C++-style namespaces.
Pair with RapidFuzz for normalize-then-match
If you’re deduping records that arrive in mixed cases, normalize first, then fuzzy-match — the rapidfuzz extension is the sibling tool:
INSTALL rapidfuzz FROM query_farm;LOAD rapidfuzz FROM query_farm;
SELECT a.id, b.id, rapidfuzz_ratio( inflector_to_snake_case(a.name), inflector_to_snake_case(b.name) ) AS simFROM left_records a, right_records bWHERE rapidfuzz_ratio( inflector_to_snake_case(a.name), inflector_to_snake_case(b.name) ) > 90;This is why both extensions share the Matching & casing group — they compose.
Platform Support
Compatibility
Extension availability may vary by platform and DuckDB version. Check below to ensure this extension supports your environment before installation.
Quick Facts
Platforms
DuckDB 2.0.0
- Linux x86_64aarch64
- Linux (musl) Not available
- macOS Apple Silicon
- Windows x86_64x86_64 (MinGW)
- WASM Not available
Compiled binary sizes
| Platform | Architecture | Size |
|---|---|---|
| Linux | x86_64 | 5.83 MB |
| Linux | aarch64 | 5.11 MB |
| macOS | Apple Silicon | 3.62 MB |
| Windows | x86_64 | 10.84 MB |
| Windows | x86_64 (MinGW) | 19.93 MB |
Compressed download sizes for the release shown above.
DuckDB & Haybarn
Release calendar- DuckDB v2.0.0 Query.Farm repository Supported
- Haybarn v1.5.6 Built-in community repository Supported
Browser examples use Haybarn-Wasm 2.0.0-rc12.
Checked .
Learn and explore
Tutorials and articles
Writing about Inflector: how it works, what changed, and why.
-
Inflector for DuckDB 2.0: unique column names and per-connection acronyms
Inflector for DuckDB 2.0 isolates acronym settings by connection, resolves renamed column collisions, and adds human-readable labels, URL slugs, and class names.