MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestPgStatioUserTablesViewColumns

Function TestPgStatioUserTablesViewColumns

server/catalog_test.go:120–163  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

118}
119
120func TestPgStatioUserTablesViewColumns(t *testing.T) {
121 db, err := sql.Open("duckdb", ":memory:")
122 if err != nil {
123 t.Fatalf("Failed to open database: %v", err)
124 }
125 defer func() { _ = db.Close() }()
126
127 if err := initPgCatalog(db, processStartTime, processStartTime, "dev", "dev"); err != nil {
128 t.Fatalf("Failed to init pg_catalog: %v", err)
129 }
130
131 expectedColumns := []string{
132 "relid", "schemaname", "relname",
133 "heap_blks_read", "heap_blks_hit",
134 "idx_blks_read", "idx_blks_hit",
135 "toast_blks_read", "toast_blks_hit",
136 "tidx_blks_read", "tidx_blks_hit",
137 }
138
139 rows, err := db.Query("SELECT * FROM pg_statio_user_tables LIMIT 1")
140 if err != nil {
141 t.Fatalf("Failed to query pg_statio_user_tables: %v", err)
142 }
143 defer func() { _ = rows.Close() }()
144
145 columns, err := rows.Columns()
146 if err != nil {
147 t.Fatalf("Failed to get columns: %v", err)
148 }
149
150 if len(columns) != len(expectedColumns) {
151 t.Errorf("Expected %d columns, got %d", len(expectedColumns), len(columns))
152 }
153
154 for i, expected := range expectedColumns {
155 if i >= len(columns) {
156 t.Errorf("Missing column %d: %s", i, expected)
157 continue
158 }
159 if columns[i] != expected {
160 t.Errorf("Column %d: expected %q, got %q", i, expected, columns[i])
161 }
162 }
163}
164
165// TestPgTypeHasComplexTypeOIDs verifies that the pg_type view includes
166// synthetic entries for PostgreSQL OIDs used by pg_attribute. Without these,

Callers

nothing calls this directly

Calls 5

initPgCatalogFunction · 0.85
CloseMethod · 0.65
QueryMethod · 0.65
ColumnsMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected