_db.TableExists<Class> stopped working on materialized views

I just update a project to 5.7.1 that uses:


To trigger a seed script that creates materialized views. Before the update it would return true is the mat view existed. After the update it returns false. Testing on normal tables works fine, it seems to just be issue with materialized view.

I am using PostgreSQL 10.9.

The behavior of TableExists<T> for PostgreSQL has not changed which checks for relkind = ‘r’ (i.e. ordinary table) where as Material views should report relkind = ‘m’ so it should not report true for materialized views.

In version 5.5.0 it returns true (desired behaviour)

In version 5.7.1 it returns false.

How can I check if a materialized view exists in 5.7.1?


The only expected behavior is what’s returned by the relkind = ‘r’ (i.e ordinary table) metadata query:

For materialized views you’d instead search for relkind = 'm' instead, in most cases (when not using a schema) this should suffice:

var sql = "SELECT COUNT(*) FROM pg_class WHERE lower(relname) = {0} AND relkind = 'm'".SqlFmt(tableName.ToLower());
var exists = dbCmd.ExecLongScalar(sql) > 0;
1 Like