PgQuoteIdent 19.0.0
dotnet add package PgQuoteIdent --version 19.0.0
NuGet\Install-Package PgQuoteIdent -Version 19.0.0
<PackageReference Include="PgQuoteIdent" Version="19.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="PgQuoteIdent" Version="19.0.0" />
<PackageReference Include="PgQuoteIdent"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add PgQuoteIdent --version 19.0.0
#r "nuget: PgQuoteIdent, 19.0.0"
#:package PgQuoteIdent@19.0.0
#addin nuget:?package=PgQuoteIdent&version=19.0.0
#tool nuget:?package=PgQuoteIdent&version=19.0.0
PgQuoteIdent
A faithful C# port of PostgreSQL's quote_identifier() function from ruleutils.c.
Quotes SQL identifiers only when needed, matching PostgreSQL's exact behavior including keyword detection. Distributed as a source-only NuGet package (no runtime dependency).
Installation
dotnet add package PgQuoteIdent
Usage
using PgQuoteIdent;
// Safe identifiers are returned as-is
PgQuoteIdentifier.QuoteIdentifier("my_table"); // "my_table"
PgQuoteIdentifier.QuoteIdentifier("foo"); // "foo"
// Reserved keywords are quoted
PgQuoteIdentifier.QuoteIdentifier("select"); // "\"select\""
PgQuoteIdentifier.QuoteIdentifier("table"); // "\"table\""
// Unsafe characters trigger quoting
PgQuoteIdentifier.QuoteIdentifier("My Table"); // "\"My Table\""
PgQuoteIdentifier.QuoteIdentifier("123abc"); // "\"123abc\""
// Embedded double quotes are escaped
PgQuoteIdentifier.QuoteIdentifier("say\"hi"); // "\"say\"\"hi\""
// Qualified identifiers (schema.table)
PgQuoteIdentifier.QuoteQualifiedIdentifier("public", "my_table");
// "public.my_table"
PgQuoteIdentifier.QuoteQualifiedIdentifier("select", "My Col");
// "\"select\".\"My Col\""
// Force-quote everything (like PostgreSQL's quote_all_identifiers GUC)
PgQuoteIdentifier.QuoteAllIdentifiers = true;
PgQuoteIdentifier.QuoteIdentifier("foo"); // "\"foo\""
How it works
The quoting logic follows PostgreSQL's rules exactly:
- An identifier is safe (no quoting) if it starts with
a-zor_, contains onlya-z,0-9,_, and is not a non-unreserved SQL keyword. - Non-unreserved keywords (
RESERVED_KEYWORD,COL_NAME_KEYWORD,TYPE_FUNC_NAME_KEYWORD) always require quoting. - Unreserved keywords (like
begin,commit,text) do not require quoting. - When quoting, embedded
"characters are doubled ("") per SQL standard.
Source-only package
This package contains no compiled assembly. The source file is compiled directly into your project, so there is zero runtime dependency. This makes it suitable for libraries that want to avoid transitive dependency chains.
Versioning
This package follows PostgreSQL-aligned versioning:
- Major version = PostgreSQL major version the keyword list is derived from
- Minor/Patch = own changes (bug fixes, improvements)
For example:
19.0.0— initial release based on PostgreSQL 19 (master) keyword list19.0.1— bug fix in C# code, same keyword list19.1.0— new feature, same keyword list20.0.0— updated keyword list for PostgreSQL 20
License
This project is licensed under the MIT License.
The identifier quoting logic is ported from PostgreSQL, which is licensed under the PostgreSQL License.
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.