finds.dev

Mazuco/pg_try_cast

TRY_CAST / TRY_CONVERT for PostgreSQL — convert values without raising errors

View on GitHub

CPostgreSQLupdated Oct 2026

// the take

A small C extension that adds SQL Server-style TRY_CAST/TRY_CONVERT to Postgres, returning NULL (or a fallback) instead of aborting the query on a bad conversion. Useful for anyone importing dirty CSV/staging data or porting SQL Server code that relies on TRY_CAST semantics.

Built on Postgres 16's actual soft-error input functions instead of the usual PL/pgSQL EXCEPTION-block hack, and the README backs up the '~16x faster' claim with a real benchmark script you can rerun yourself. It correctly handles the fiddly cases most people get wrong: varchar(n) truncation vs NULL, numeric(p,s) rounding/overflow, and domain CHECK constraints. Ships with CI, a regression test suite (test/sql + test/expected), and a Dockerfile for quick trial.

Zero stars, zero forks, brand new — there's no track record of it surviving contact with real production data yet. Hard-locked to Postgres 16+ because of the pg_input_is_valid dependency, so it's useless on anything older, which is often exactly where messy legacy data lives. Being a C extension means you need build tooling and pg_config on the server; that's a non-starter on most managed Postgres (RDS, Azure Flexible Server, Supabase) unless you're self-hosting or building a custom image. It also only converts from text, not between arbitrary types, so despite the SQL Server comparison table it's not a drop-in replacement for every TRY_CAST use case.

We read the README, the directory tree and a key source file in October 2026. Nobody pays to be listed. How we judge →

// at a glance

Stars
0
Forks
0
Language
C
License
PostgreSQL
Last commit
17 Oct 2026

// nearby

If pg_try_cast isn't quite it.

All repos →