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

Function TestArrayLowerCompatibilityMacro

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

Source from the content-addressed store, hash-verified

307}
308
309func TestArrayLowerCompatibilityMacro(t *testing.T) {
310 db, err := sql.Open("duckdb", ":memory:")
311 if err != nil {
312 t.Fatalf("Failed to open database: %v", err)
313 }
314 defer func() { _ = db.Close() }()
315
316 if err := initPgCatalog(db, processStartTime, processStartTime, "dev", "dev"); err != nil {
317 t.Fatalf("Failed to init pg_catalog: %v", err)
318 }
319
320 tests := []struct {
321 name string
322 query string
323 want sql.NullInt64
324 }{
325 {
326 name: "one dimensional non-empty array",
327 query: "SELECT array_lower(ARRAY[1, 2, 3], 1)",
328 want: sql.NullInt64{Int64: 1, Valid: true},
329 },
330 {
331 name: "empty array",
332 query: "SELECT array_lower(ARRAY[]::INTEGER[], 1)",
333 want: sql.NullInt64{},
334 },
335 {
336 name: "null array",
337 query: "SELECT array_lower(NULL::INTEGER[], 1)",
338 want: sql.NullInt64{},
339 },
340 {
341 name: "unsupported dimension",
342 query: "SELECT array_lower(ARRAY[1, 2, 3], 2)",
343 want: sql.NullInt64{},
344 },
345 {
346 name: "null dimension",
347 query: "SELECT array_lower(ARRAY[1, 2, 3], NULL)",
348 want: sql.NullInt64{},
349 },
350 }
351
352 for _, tt := range tests {
353 t.Run(tt.name, func(t *testing.T) {
354 var got sql.NullInt64
355 if err := db.QueryRow(tt.query).Scan(&got); err != nil {
356 t.Fatalf("%s failed: %v", tt.query, err)
357 }
358 if got.Valid != tt.want.Valid || got.Int64 != tt.want.Int64 {
359 t.Fatalf("array_lower result = %+v, want %+v", got, tt.want)
360 }
361 })
362 }
363}
364
365func TestUtilityMacrosWithoutPgCatalog(t *testing.T) {
366 // Verify that initUtilityMacros works independently of initPgCatalog,

Callers

nothing calls this directly

Calls 5

initPgCatalogFunction · 0.85
CloseMethod · 0.65
RunMethod · 0.65
ScanMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected