PG
PRO
22024ERRORTier 2 — Caution✅ HIGH confidence

unterminated C string

Category: Data ExceptionVersions: All Postgres versions

What this means

SQLSTATE 22024 is raised when a C-style string (null-terminated) passed to a low-level Postgres function does not have a proper null terminator. This is typically a bug in a C extension or driver.

Why it happens

  1. 1A C extension or low-level driver passes a non-null-terminated string to a Postgres function expecting a C string

How to reproduce

Buggy C extension passing unterminated string data.

trigger — this will ERROR
ERROR: unterminated C string

Fix 1: Fix the C extension to properly null-terminate strings

When developing or debugging a Postgres C extension.

fix

Why this works

In C extension code, ensure all strings passed to Postgres functions via palloc or cstring operations are properly null-terminated.

Sources

📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html

🔧 Source ref: Class 22 — Data Exception

Confidence assessment

✅ HIGH confidence

Standard SQLSTATE. Only relevant to C extension development.

See also

🔗 Related errors

📄 Reference pages

Postgres C Extensions
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →