
Security News
Socket Releases Free Certified Patches for Nuxt Security Vulnerabilities
Socket releases free Certified Patches for high-severity Nuxt vulnerabilities, including server-side remote code execution through server island props.
@pgsql/quotes
Advanced tools
PostgreSQL identifier quoting and keyword classification utilities. A faithful TypeScript port of PostgreSQL's quote_identifier() from ruleutils.c, with full keyword classification from kwlist.h.
npm install @pgsql/quotes
import { QuoteUtils } from '@pgsql/quotes';
// Simple identifiers are not quoted
QuoteUtils.quoteIdentifier('my_table'); // 'my_table'
// Reserved keywords are quoted
QuoteUtils.quoteIdentifier('select'); // '"select"'
QuoteUtils.quoteIdentifier('table'); // '"table"'
// Unreserved keywords are not quoted
QuoteUtils.quoteIdentifier('schema'); // 'schema'
// Identifiers with uppercase or special chars are quoted
QuoteUtils.quoteIdentifier('MyTable'); // '"MyTable"'
QuoteUtils.quoteIdentifier('my-table'); // '"my-table"'
// Embedded double quotes are escaped
QuoteUtils.quoteIdentifier('a"b'); // '"a""b"'
import { QuoteUtils } from '@pgsql/quotes';
// Schema-qualified names
QuoteUtils.quoteQualifiedIdentifier('public', 'my_table');
// 'public.my_table'
// Dotted names (first part strict, rest relaxed)
QuoteUtils.quoteDottedName(['public', 'my_table']);
// 'public.my_table'
// Keywords after dot don't need quoting (PostgreSQL grammar rule)
QuoteUtils.quoteDottedName(['select', 'select']);
// '"select".select'
import { QuoteUtils } from '@pgsql/quotes';
// Type names allow col_name and type_func_name keywords unquoted
QuoteUtils.quoteIdentifierTypeName('json'); // 'json'
QuoteUtils.quoteIdentifierTypeName('integer'); // 'integer'
QuoteUtils.quoteIdentifierTypeName('boolean'); // 'boolean'
// Only reserved keywords are quoted in type position
QuoteUtils.quoteIdentifierTypeName('select'); // '"select"'
// Schema-qualified type names
QuoteUtils.quoteTypeDottedName(['public', 'json']); // 'public.json'
import { QuoteUtils } from '@pgsql/quotes';
// Escape string literals
QuoteUtils.escape('hello'); // "'hello'"
QuoteUtils.escape("it's"); // "'it''s'"
// E-string formatting (auto-detects need for E prefix)
QuoteUtils.formatEString('a\\b'); // "E'a\\\\b'"
QuoteUtils.formatEString('hello'); // "'hello'"
import { keywordKindOf } from '@pgsql/quotes';
import type { KeywordKind } from '@pgsql/quotes';
keywordKindOf('select'); // 'RESERVED_KEYWORD'
keywordKindOf('schema'); // 'UNRESERVED_KEYWORD'
keywordKindOf('json'); // 'COL_NAME_KEYWORD'
keywordKindOf('join'); // 'TYPE_FUNC_NAME_KEYWORD'
keywordKindOf('foo'); // 'NO_KEYWORD'
import {
RESERVED_KEYWORDS,
UNRESERVED_KEYWORDS,
COL_NAME_KEYWORDS,
TYPE_FUNC_NAME_KEYWORDS,
} from '@pgsql/quotes';
RESERVED_KEYWORDS.has('select'); // true
COL_NAME_KEYWORDS.has('json'); // true
| Method | Description |
|---|---|
escape(literal) | Wraps a string in single quotes, escaping embedded quotes |
escapeEString(value) | Escapes backslashes and single quotes for E-string literals |
formatEString(value) | Auto-detects and formats E-prefixed string literals |
needsEscapePrefix(value) | Checks if a value needs E-prefix escaping |
quoteIdentifier(ident) | Quotes an identifier if needed (port of PG's quote_identifier) |
quoteIdentifierAfterDot(ident) | Quotes for lexical reasons only (post-dot position) |
quoteDottedName(parts) | Quotes a multi-part dotted name (e.g., schema.table) |
quoteQualifiedIdentifier(qualifier, ident) | Quotes a two-part qualified name |
quoteIdentifierTypeName(ident) | Quotes an identifier in type-name context |
quoteTypeDottedName(parts) | Quotes a multi-part dotted type name |
Returns the keyword classification for a given word. Case-insensitive.
Returns one of: 'NO_KEYWORD', 'UNRESERVED_KEYWORD', 'COL_NAME_KEYWORD', 'TYPE_FUNC_NAME_KEYWORD', 'RESERVED_KEYWORD'.
To regenerate the keyword list from a PostgreSQL source tree:
npm run keywords -- ~/path/to/postgres/src/include/parser/kwlist.h
This parses PostgreSQL's kwlist.h and regenerates src/kwlist.ts.
🛠 Built by the Constructive team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on GitHub.
pgsql-parser.pgsql-parser for parsing and deparsing SQL queries.AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
No developer or entity involved in creating Software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the Software code or Software CLI, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
FAQs
PostgreSQL identifier quoting and keyword classification utilities
The npm package @pgsql/quotes receives a total of 317,125 weekly downloads. As such, @pgsql/quotes popularity was classified as popular.
We found that @pgsql/quotes demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket releases free Certified Patches for high-severity Nuxt vulnerabilities, including server-side remote code execution through server island props.

Security News
An open letter signed by 50 companies, from NVIDIA and Microsoft to Mistral and Hugging Face, urges Washington not to restrict open weight AI.

Security News
/Research
A fake corepack.org site is impersonating the Node.js tool and delivers an infostealer and proxyware to developers who download it.