Repository navigation
Conversation
PostgreSQL parses a quoted literal with the input function of the type it is compared to. The '1970-01-01' stand-in for a non-constant string parameter is therefore rejected by uuid, jsonb, enum, inet and integer columns (SQLSTATE 22P02). The query got no result type, and the rules reported a false error. On PostgreSQL, replace such parameters with an untyped NULL instead. PostgreSQL resolves it from context like a bind parameter, never runs a type input function on it, and picks the same function overloads and result column types as for the quoted literal. Only non-constant, non-numeric strings change, including nullable strings and lists of strings. Constant, numeric, int, bool, float and DateTime parameters keep their simulated values, and MySQL/MariaDB is unaffected. PostgreSQL is detected through the reflector's datasource, so wrapped reflectors such as RecordingQueryReflector are recognised as well.
devfrey
force-pushed
the
fix-600-pgsql-uuid-params
branch
from
November 13, 2026 15:52
7c511d1 to
55e6d96
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #600
This makes queries that compare a uuid column with a string parameter work on PostgreSQL.
Before, a query like this got no result type, and phpstan-dba reported an error for it:
phpstan-dba checks a query by running it with a stand-in value for each parameter. For strings that stand-in was a date,
'1970-01-01'. MySQL accepts that for most columns, but PostgreSQL rejects it for a uuid column because it isn't a valid uuid. jsonb, enum and inet columns had the same problem.On PostgreSQL, string parameters are now filled in as
NULLinstead. PostgreSQL acceptsNULLfor every column type, so the query runs and the result type is inferred again:phpstan-dba only looks at the result columns, so it doesn't matter that no rows match.
I tried a range of query shapes on Postgres 14 and 18 (
IN,ANY,coalesce,CASE, function calls,INSERTandUPDATE).NULLgives the same result types as the old date value. The one exception is theDATE :xsyntax, which doesn't work with real prepared statements either.What stays the same:
Tests: I added a uuid table to the PostgreSQL test schema, with type inference and rule tests for uuid, jsonb and enum columns. Four existing PostgreSQL error expectations now show
NULLwhere they used to show the date.One thing to be aware of: PostgreSQL is detected through the database connection, and
ReplayQueryReflectorandChainedReflectordon't have one. In those setups the old date value is still used. In replay mode, the queries then wouldn't match the recorded ones. Record and replay isn't supported on PostgreSQL yet (#353), so nothing breaks today, but it will need handling when that is added.