stringifyValueForSQL
stringifyValueForSQL(v, options?, encode?)
| Parameter | Type | Description |
|---|---|---|
| v | any | The value to stringify |
| options | DataMappingOptions | Data mapping options passed through to encode |
| encode | EncodeTextFunction | Function used to encode non-primitive values |
Returns: string
Converts a single JS value into a SQL-literal-safe expression for splicing into SQL text: null for null/undefined, true/false for booleans, an ARRAY[...] expression for arrays (via stringifyArrayForSQL; unlike the parameter path, this always writes one, with no unspecified-text shortcut for a numeric array), a quoted '...'::uuid for UUID strings, a bare quoted literal with no cast for a Date (its own offset included, so it means the same inlined as it does bound) or a plain string, and an escaped bare literal for a number/bigint.
For any other object, DataTypeMap.determine() is asked which type it is, the same way it would be if the value were bound as a parameter instead, so a Point, a Range, an Interval, or a Buffer is written through that type's own encodeText() and cast, e.g. '(1,2)'::point, rather than through JSON.stringify. Only an object no registered type claims falls back to a quoted '...'::json. A Range built without a type OID throws instead of silently becoming JSON (see API: Range), since nothing about a bare Range says which of the six range types it's meant to be.