Skip to content
Search
DSL · Pg query

typed

Definition

/**
 * Wrap a value with explicit PostgreSQL type information for parameter binding.
 *
 * Use when auto-detection isn't sufficient or when you need to specify
 * the exact PostgreSQL type (since one PHP type can map to multiple PostgreSQL types):
 * - int could be INT2, INT4, or INT8
 * - string could be TEXT, VARCHAR, or CHAR
 * - array must always use typed() since auto-detection cannot determine element type
 * - DateTimeInterface could be TIMESTAMP or TIMESTAMPTZ
 * - Json could be JSON or JSONB
 *
 * @param mixed $value The value to bind
 * @param ValueType $targetType The PostgreSQL type to convert the value to
 *
 * @example
 * $client->fetch(
 *     'SELECT * FROM users WHERE id = $1 AND tags = $2',
 *     [
 *         typed('550e8400-e29b-41d4-a716-446655440000', ValueType::UUID),
 *         typed(['tag1', 'tag2'], ValueType::TEXT_ARRAY),
 *     ]
 * );
 */
typed(?mixed $value, ValueType $targetType) : TypedValue

Contributors

Built in the open.

Join us on GitHub
scroll back to top