Skip to content

Change postgresql to use concat() instead of || - #19584

Open
othercorey wants to merge 1 commit into
cakephp:5.nextfrom
othercorey:postgres-concat
Open

Change postgresql to use concat() instead of ||#19584
othercorey wants to merge 1 commit into
cakephp:5.nextfrom
othercorey:postgres-concat

Conversation

@othercorey

Copy link
Copy Markdown
Contributor

I think this change probably belongs in 6.0.

PostgreSQL added concat() in 9.1 with proper support for NULL arguments - they are ignored instead of returning NULL

In postgrs, bound parameters have to be cast to text to satisfy the variadic arguments since it requires types be known at compile time to support argument overloading.

The concat() function should be what we want and only be safer, but since it would change the return type for NULL arguments, it's not technically backwards compatible.

@othercorey
othercorey force-pushed the postgres-concat branch 2 times, most recently from 210249f to dc28882 Compare August 5, 2026 03:10
@othercorey

Copy link
Copy Markdown
Contributor Author

@markstory Because only the bound parameters are cast, we could use the postgres shorthand :parm0::text if we wanted to keep the sql simpler.

Comment on lines +254 to +261
$driver = Mockery::mock(Postgres::class)
->makePartial()
->shouldAllowMockingProtectedMethods();
$driver->__construct([]);
$driver->shouldReceive('enabled')->andReturn(true);
$driver->shouldReceive('connect')->andReturnNull();
$driver->shouldReceive('getPdo')->andReturn(Mockery::mock(PDO::class));
$driver->shouldReceive('version')->andReturn('16.0');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this mock necessary? We could skip the test if the postgres version is too low instead.

@othercorey othercorey Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this mock necessary? We could skip the test if the postgres version is too low instead.

Not sure. It was just following other examples. It just tests sql generation on all builds I guess. Other tests already include concat(). I can double-check they test different parameter types.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to use postgres connection and verify sql. The FunctionsBuilder test just checks we generate a valid function expression.

@markstory markstory added this to the 5.5.0 milestone Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants