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

Function TestEmptyTableOperations

tests/integration/edge_cases_test.go:845–934  ·  view source on GitHub ↗

TestEmptyTableOperations tests operations on tables with no rows. Note: basic empty SELECT is covered by TestProtocolSimpleQuery/empty_result. These tests cover UPDATE/DELETE returning 0 rows affected, aggregate NULL behavior, and JOINs where one side is empty.

(t *testing.T)

Source from the content-addressed store, hash-verified

843// These tests cover UPDATE/DELETE returning 0 rows affected, aggregate NULL
844// behavior, and JOINs where one side is empty.
845func TestEmptyTableOperations(t *testing.T) {
846 t.Run("update_empty", func(t *testing.T) {
847 conn := openDuckgresConn(t)
848 defer func() { _ = conn.Close() }()
849
850 mustExec(t, conn, "CREATE TABLE empty_update (id INTEGER, val TEXT)")
851
852 result, err := conn.Exec("UPDATE empty_update SET val = 'changed' WHERE id = 1")
853 if err != nil {
854 t.Fatalf("UPDATE on empty table failed: %v", err)
855 }
856 affected, _ := result.RowsAffected()
857 if affected != 0 {
858 t.Errorf("Expected 0 rows affected, got %d", affected)
859 }
860
861 mustExec(t, conn, "DROP TABLE empty_update")
862 })
863
864 t.Run("delete_empty", func(t *testing.T) {
865 conn := openDuckgresConn(t)
866 defer func() { _ = conn.Close() }()
867
868 mustExec(t, conn, "CREATE TABLE empty_delete (id INTEGER)")
869
870 result, err := conn.Exec("DELETE FROM empty_delete WHERE id = 1")
871 if err != nil {
872 t.Fatalf("DELETE on empty table failed: %v", err)
873 }
874 affected, _ := result.RowsAffected()
875 if affected != 0 {
876 t.Errorf("Expected 0 rows affected, got %d", affected)
877 }
878
879 mustExec(t, conn, "DROP TABLE empty_delete")
880 })
881
882 t.Run("aggregate_empty", func(t *testing.T) {
883 conn := openDuckgresConn(t)
884 defer func() { _ = conn.Close() }()
885
886 mustExec(t, conn, "CREATE TABLE empty_agg (id INTEGER, val DOUBLE)")
887
888 var count int
889 if err := conn.QueryRow("SELECT COUNT(*) FROM empty_agg").Scan(&count); err != nil {
890 t.Fatalf("COUNT on empty failed: %v", err)
891 }
892 if count != 0 {
893 t.Errorf("COUNT: expected 0, got %d", count)
894 }
895
896 var sum sql.NullFloat64
897 if err := conn.QueryRow("SELECT SUM(val) FROM empty_agg").Scan(&sum); err != nil {
898 t.Fatalf("SUM on empty failed: %v", err)
899 }
900 if sum.Valid {
901 t.Errorf("SUM: expected NULL, got %f", sum.Float64)
902 }

Callers

nothing calls this directly

Calls 7

openDuckgresConnFunction · 0.85
mustExecFunction · 0.85
RunMethod · 0.65
CloseMethod · 0.65
ExecMethod · 0.65
RowsAffectedMethod · 0.65
ScanMethod · 0.65

Tested by

no test coverage detected