Skip to content

Commit

Permalink
Add support for pg_matviews
Browse files Browse the repository at this point in the history
  • Loading branch information
exAspArk committed Jan 6, 2025
1 parent e15537c commit b2df4ff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/query_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ func TestHandleQuery(t *testing.T) {
"types": {Uint32ToString(pgtype.BoolOID)},
"values": {},
},
"SELECT schemaname, matviewname AS objectname FROM pg_catalog.pg_matviews": {
"description": {"schemaname", "objectname"},
"types": {Uint32ToString(pgtype.BoolOID), Uint32ToString(pgtype.BoolOID)},
"values": {},
},
// pg_namespace
"SELECT DISTINCT(nspname) FROM pg_catalog.pg_namespace WHERE nspname != 'information_schema' AND nspname != 'pg_catalog'": {
"description": {"nspname"},
Expand Down
1 change: 1 addition & 0 deletions src/query_parser_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ var PG_SYSTEM_TABLES = NewSet([]string{
"pg_language",
"pg_largeobject",
"pg_largeobject_metadata",
"pg_matviews",
"pg_namespace",
"pg_opclass",
"pg_operator",
Expand Down
15 changes: 15 additions & 0 deletions src/select_remapper_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
PG_TABLE_PG_AUTH_MEMBERS = "pg_auth_members"
PG_TABLE_PG_USER = "pg_user"
PG_TABLE_PG_STAT_ACTIVITY = "pg_stat_activity"
PG_TABLE_PG_MATVIEWS = "pg_matviews"

PG_TABLE_TABLES = "tables"
)
Expand Down Expand Up @@ -106,6 +107,10 @@ func (remapper *SelectRemapperTable) RemapTable(node *pgQuery.Node) *pgQuery.Nod
// pg_stat_activity -> return empty table
tableNode := parser.MakeEmptyTableNode(PG_TABLE_PG_STAT_ACTIVITY, PG_STAT_ACTIVITY_COLUMNS, qSchemaTable.Alias)
return remapper.overrideTable(node, tableNode)
case PG_TABLE_PG_MATVIEWS:
// pg_matviews -> return empty table
tableNode := parser.MakeEmptyTableNode(PG_TABLE_PG_MATVIEWS, PG_MATVIEWS_COLUMNS, qSchemaTable.Alias)
return remapper.overrideTable(node, tableNode)
default:
// pg_catalog.pg_* other system tables -> return as is
return node
Expand Down Expand Up @@ -285,3 +290,13 @@ var PG_STAT_ACTIVITY_COLUMNS = []string{
"query",
"backend_type",
}

var PG_MATVIEWS_COLUMNS = []string{
"schemaname",
"matviewname",
"matviewowner",
"tablespace",
"hasindexes",
"ispopulated",
"definition",
}

0 comments on commit b2df4ff

Please sign in to comment.