Skip to content

Inflector

String case transformation and English inflection inside SQL.

213,170
extension loads · last 90 days
On this page

Technical Overview

Rails-style string shaping, without the Ruby

Caveats — read these first

  • Pluralization is English-only: Singular/plural rules come from the upstream cruet crate, whose ruleset and irregular-word table are English. It handles real English irregulars well — personpeople, mousemice, analysisanalyses — but has no awareness of French, German, Spanish, or any other language. Non-English input silently produces mechanical English-rule output. For multilingual content, inflect upstream and store the result.
  • Case transforms are mechanical, not semantic: The tokenizer treats acronyms as runs of capitals, so inflector_to_snake_case('XMLHttpRequest') yields xml_http_request. That is correct for column-naming work; if you need acronym-preservation rules tuned to your domain, do that step in application code first.
  • Pluralization isn't always reversible: peopleperson round-trips fine, but English has true ambiguities — data is both singular and plural in modern usage, and species and series are unchanged. Don't round-trip a value through plural-then-singular and assume identity.
  • Single-character tokens are skipped: The case tokenizer requires a two-character minimum and ignores 1-character runs, which matters for inputs like aB or single-letter prefixes — those tokens are dropped rather than preserved.

How it works

  • Upstream provenance: The actual rule engine — case tokenization, pluralization, the irregular-word tables, the ActiveSupport-style helpers — lives in cruet and convert_case. Inflector is a binding layer that surfaces those crates as DuckDB functions, so behavior tracks the upstream crates rather than being reimplemented.
  • Scalar functions for a known target: When the target case is known at parse time, there's a dedicated scalar function per case, plus a matching is_* predicate for routing a value based on its current shape. String in, string out — vectorized like any other DuckDB scalar.
  • One polymorphic dispatcher across shapes: inflect takes the case as a runtime argument and is polymorphic on its payload: a VARCHAR returns a transformed string, a STRUCT returns the same struct with every key renamed (values untouched), and a parenthesized query becomes a table function that rewrites every column name. Same function, three shapes — the headline path for normalizing a whole result set in one call.

Inflector vs. RapidFuzz

  • Inflector: deterministic transformation: Reach for Inflector when you know exactly what shape you want — snake_case, kebab-case, plural, a foreign-key name — and need to mechanically produce it from a single input. The output is fully determined by the input and the chosen rule.
  • RapidFuzz: fuzzy comparison: Reach for rapidfuzz when you have two strings and want a similarity score — record linkage, dedupe, spell-check. That's comparison, not transformation. The two compose well: normalize naming with Inflector, then fuzzy-match across the normalized values with RapidFuzz.

Deep Dive

Technical Details

Install

INSTALL inflector FROM community;
LOAD inflector;

Quick Start

Single-value case transforms

SELECT inflector_to_camel_case('hello_world');   -- helloWorld
SELECT inflector_to_snake_case('HelloWorld');    -- hello_world
SELECT inflector_to_kebab_case('helloWorld');    -- hello-world

Pluralize / singularize English words

SELECT inflector_to_plural('person');            -- people
SELECT inflector_to_singular('mice');            -- mouse

Rewrite every key in a struct / result set

SELECT inflect('snake', {'firstName':'John','lastName':'Doe'});
SELECT * FROM inflect('kebab', (FROM read_csv('data.csv')));

Reference

Extension Contents

Quick reference to all available functions and settings organized by category.

Name Description
Bulk
inflect() 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
inflector_to_camel_case() Convert to camelCase.
inflector_to_class_case() Convert to ClassCase (PascalCase singular).
inflector_to_kebab_case() Convert to kebab-case (hyphen-separated).
inflector_to_lower_case() Lowercase every character.
inflector_to_pascal_case() Convert to PascalCase.
inflector_to_screamingsnake_case() Convert to SCREAMING_SNAKE_CASE (caps with underscores).
inflector_to_sentence_case() Convert to Sentence case — first letter capital, rest lowercase, words space-separated.
inflector_to_snake_case() Convert to snake_case.
inflector_to_title_case() Convert to Title Case — every word capitalized, space-separated.
inflector_to_train_case() Convert to Train-Case (capitalized hyphenated).
inflector_to_upper_case() Uppercase every character.
Configuration
inflector_acronyms List of acronyms preserved as uppercase in case conversions (e.g., HTML, API)
Functions
inflector_deconstantize() Removes the rightmost segment from a constant expression
inflector_demodulize() Removes the module part from a fully qualified name
inflector_deordinalize() Removes the ordinal suffix from a string (1st -> 1)
inflector_is_camel_case() Returns true if the string is in camelCase format
inflector_is_class_case() Returns true if the string is in ClassCase (PascalCase) format
inflector_is_foreign_key() Returns true if the string is in foreign key format (ends with _id)
inflector_is_kebab_case() Returns true if the string is in kebab-case format
inflector_is_pascal_case() Returns true if the string is in PascalCase format
inflector_is_screamingsnake_case() Returns true if the string is in SCREAMING_SNAKE_CASE format
inflector_is_sentence_case() Returns true if the string is in Sentence case format
inflector_is_snake_case() Returns true if the string is in snake_case format
inflector_is_table_case() Returns true if the string is in table_case format (snake_case plural)
inflector_is_title_case() Returns true if the string is in Title Case format
inflector_is_train_case() Returns true if the string is in Train-Case format
inflector_ordinalize() Converts a number string to its ordinal form (1st, 2nd, 3rd, etc.)
inflector_to_foreign_key() Converts a class name to a foreign key column name
Inflection
inflector_to_plural() Pluralize an English word — handles irregulars (person→people, mouse→mice).
inflector_to_singular() Singularize an English word.
Naming Helpers
inflector_to_table_case() Rails-style 'table_case' — snake_case + plural.

API Reference

Function Documentation

Configuration

Settings

Configure the inflector extension behavior using these settings.

inflector_acronyms

Default Value: []

Practical Examples

Cookbook

Real-world recipes and patterns for common use cases.

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

Release status Stable
Software License MIT
Pricing Free
Written In Rust
Source Available Yes
View on GitHub
Usage
213,170
loads · last 90 days

Platforms

  • Linux x86_64 aarch64
  • Linux (musl) Not available
  • macOS Intel Apple Silicon
  • Windows x86_64
  • WASM eh mvp threads
Compiled binary sizes
Platform Architecture Size
Linux x86_64 4.94 MB
Linux aarch64 4.52 MB
macOS Intel 2.89 MB
macOS Apple Silicon 2.55 MB
Windows x86_64 8.01 MB
WASM eh 500.4 KB
WASM mvp 571.8 KB
WASM threads 336.1 KB

Compressed download size from the Haybarn extension repository.

DuckDB & Haybarn

Release calendar