• API
  • Utilities

Utility Functions

pg.escapeIdentifier

Escapes a string as a SQL identifier.

const { escapeIdentifier } = require('pg')
const escapedIdentifier = escapeIdentifier('FooIdentifier')
console.log(escapedIdentifier) // '"FooIdentifier"'

pg.escapeLiteral

⚠️

Note: Instead of manually escaping SQL literals, it is recommended to use parameterized queries. Refer to parameterized queries and the client.query API for more information.

Escapes a string as a SQL literal.

const { escapeLiteral } = require('pg')
const escapedLiteral = escapeLiteral("hello 'world'")
console.log(escapedLiteral) // "'hello ''world'''"