Schema::tableExists does not find views for PostgreSQL

Created on 23 June 2024, 6 months ago
Updated 17 July 2024, 5 months ago

That was already reported in 📌 Database::tableExists optimization for PostgreSQL Fixed (#29).

Default implementation of Schema::tableExists does not distinguish table and views. However it does not work anymore for Postgres database since tableExists has been overridden in Postgres driver

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Database 

Last updated 2 days ago

  • Maintained by
  • 🇳🇱Netherlands @daffie
Created by

🇷🇺Russia Chi

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Chi
  • 🇷🇺Russia Chi

    Actually I think the default behavior is wrong. tableExists() method should not look for views. First of all it's not comply with its name. Second it causes errors when doing schema alterations as other Schema methods relies on tableExists().

    A simple example to demonstrate the problem.

    $schema = \Drupal::database()->schema();
    
    if ($schema->tableExists('some_view')) {
      $schema->dropTable('some_view');
    }
    

    The above code returns the following error on MySQL database.

      SQLSTATE[42S02]: Base table or view not found: 1965 'd10.some_view' is a view  
    
  • 🇳🇿New Zealand quietone

    Fixes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.

Production build 0.71.5 2024