PG::TextEncoder::
QuotedLiteral class
Superclass | PG::CompositeEncoder |
This is the encoder class for PostgreSQL literals.
A literal is quoted and escaped by the '
character, so that it can be inserted into SQL queries. It works equal to PG::Connection#escape_literal
, but integrates into the type cast system of ruby-pg.
Both expressions have the same result:
conn.escape_literal(PG::TextEncoder::Array.new.encode(["v1","v2"])) # => "'{v1,v2}'" PG::TextEncoder::QuotedLiteral.new(elements_type: PG::TextEncoder::Array.new).encode(["v1","v2"]) # => "'{v1,v2}'"
While escape_literal requires a intermediate ruby string allocation, QuotedLiteral
encodes the values directly to the result string.