0

From what I can tell CakePHP 3.x support claims support for PostgreSQL 8+ but in practice I found that out of the box there is a missing cast before PostgreSQL 8.3 for regclass::text. If you attempt a simple model in CakePHP 3 you will get an error similar to this

There was 1 error:

1) App\Test\TestCase\Model\Table\SampleListsTableTest::testFoo
Cake\Database\Exception: SQLSTATE[42846]: Cannot coerce: 7 ERROR:      cannot cast type regclass to text
LINE 11: ...  pg_get_serial_sequence(attr.attrelid::regclass::text, attr...

This is because the regclass::text cast does not exist until PostgreSQL 8.3. I checked this on multiple instances I have of PostgreSQL 8.2. The fix is rather easy but not immediately obvious.

DROP CAST IF EXISTS (regclass AS text);
CREATE OR REPLACE FUNCTION public.text(regclass) RETURNS text STRICT
STABLE AS '
SELECT pg_catalog.textin(pg_catalog.regclassout($1::regclass));'
LANGUAGE 'SQL';
CREATE CAST (regclass AS text) WITH FUNCTION public.text(regclass);

I'm not sure if this should be considered a bug in CakePHP 3.x or if it should be included as a caveat for older Postgres support in the install notes but either way if someone could confirm this behavior that would be great.

carcus88
  • 137
  • 1
  • 7
  • This would be better suited on their github issue tracker than in here. – KaffineAddict Oct 11 '17 at 19:30
  • Please report issues with the framework here https://github.com/cakephp/cakephp/issues and please *only* issues. – floriank Oct 11 '17 at 19:51
  • The reason I posted here was that I'm not sure if this is an issue or something strange with my setup and I was hoping someone with more postgres expertise could confirm when the regclass::text cast became available. – carcus88 Oct 11 '17 at 20:50
  • 1
    I think it's a problem of CakePHP and already brought it to the attention of the core team. The problem seems to be BC breaking changes are more or less common between different PG versions. So it's hard to get them all handled. We'll investigate this issue further. Please just copy and paste your question to the Github issues so the core team can discuss your problem there. Thank you! :) – floriank Oct 11 '17 at 22:37
  • Created an issue for this on GitHub https://github.com/cakephp/cakephp/issues/11321 – carcus88 Oct 12 '17 at 15:14

0 Answers0