-
Notifications
You must be signed in to change notification settings - Fork 205
Bug: search_objects does not return comments for views #296
Description
(I'm running on Postgres v17, in case that's relevant)
Summary
When using search_objects with object_type: "table" and detail_level: "full" (or "summary"), the comment field is populated for real tables but always null for views, even when a COMMENT ON VIEW has been set.
Minimal reproduction
-- Setup: create a view with a comment
CREATE SCHEMA test_schema;
CREATE TABLE test_schema.real_table (id int);
CREATE VIEW test_schema.my_view AS SELECT * FROM test_schema.real_table;
COMMENT ON TABLE test_schema.real_table IS 'This is a real table comment';
COMMENT ON VIEW test_schema.my_view IS 'This is a view comment';
-- Verify comments exist in pg_catalog
SELECT c.relname, c.relkind, obj_description(c.oid) AS comment
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname = 'test_schema';| relname | relkind | comment |
|---|---|---|
| real_table | r | This is a real table comment |
| my_view | v | This is a view comment |
Now call search_objects:
{
"object_type": "table",
"schema": "test_schema",
"detail_level": "full"
}Expected: both real_table and my_view include their comment in the response.
Actual: real_table has "comment": "This is a real table comment", but my_view has no comment field.
Root cause
In src/connectors/postgres/index.ts, getTableComment() (around line 369) filters by relkind:
SELECT obj_description(c.oid) as table_comment
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname = $1
AND n.nspname = $2
AND c.relkind IN ('r','p','m','f')The filter ('r','p','m','f') covers regular tables, partitioned tables, materialized views, and foreign tables — but excludes 'v' (ordinary views). Since getTables() queries information_schema.tables which does return views, they appear in search_objects results but with a null comment.
Proposed fix
Add 'v' to the relkind filter in getTableComment():
- AND c.relkind IN ('r','p','m','f')
+ AND c.relkind IN ('r','p','m','f','v')This is a one-character fix. obj_description() works identically for views and tables — it just reads from pg_description by OID.