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

Function TestPgStatActivityColumnsAndOIDs

server/conn_test.go:3820–3851  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3818 {"SELECT $10", 10},
3819 {"INSERT INTO t VALUES ($1, $2, $3)", 3},
3820 {"SELECT * FROM t WHERE id = $1 AND name = $3", 3},
3821 {"", 0},
3822 {"SELECT '$1'", 1}, // simplified: doesn't parse string literals
3823 }
3824
3825 for _, tt := range tests {
3826 got := countDollarParams(tt.query)
3827 if got != tt.expected {
3828 t.Errorf("countDollarParams(%q) = %d, want %d", tt.query, got, tt.expected)
3829 }
3830 }
3831}
3832
3833func TestMatchPgStatActivityQuery(t *testing.T) {
3834 tests := []struct {
3835 name string
3836 query string
3837 want bool
3838 }{
3839 // Should match
3840 {"simple select", "SELECT * FROM pg_stat_activity", true},
3841 {"pg_catalog prefix", "SELECT * FROM pg_catalog.pg_stat_activity", true},
3842 {"pg_catalog with spaces", "SELECT * FROM pg_catalog . pg_stat_activity", true},
3843 {"case insensitive FROM", "select * from pg_stat_activity", true},
3844 {"uppercase FROM keyword", "SELECT * FROM pg_stat_activity", true},
3845 // Note: strings.Contains fast path is case-sensitive for the table name.
3846 // This is fine because PostgreSQL clients always send lowercase catalog names.
3847 {"uppercase table name skipped by fast path", "select * from PG_STAT_ACTIVITY", false},
3848 {"with where clause", "SELECT pid, usename FROM pg_stat_activity WHERE state = 'active'", true},
3849 {"with limit", "SELECT * FROM pg_stat_activity LIMIT 10", true},
3850 {"with count", "SELECT count(*) FROM pg_stat_activity", true},
3851 {"multiline", "SELECT pid\nFROM pg_stat_activity\nWHERE state = 'active'", true},
3852 {"tab before table", "SELECT * FROM\tpg_stat_activity", true},
3853 {"multiple spaces", "SELECT * FROM pg_stat_activity", true},
3854

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected