index_predicate_test.go 917 B

1234567891011121314151617181920212223242526272829303132333435
  1. package pgserver
  2. import "testing"
  3. func TestIndexedEqualityPreservesSQLNullAndFloatSemantics(t *testing.T) {
  4. c, client := newDataConnection(t)
  5. for _, sql := range []string{
  6. "CREATE TABLE t (id INTEGER PRIMARY KEY, v REAL)",
  7. "INSERT INTO t VALUES (1,1.0000001),(2,1.0000002),(3,NULL)",
  8. "CREATE INDEX t_v ON t(v)",
  9. } {
  10. runQuery(t, c, client, &Message{Type: MsgQuery, Data: append([]byte(sql), 0)})
  11. }
  12. for _, tc := range []struct {
  13. sql string
  14. rows int
  15. }{
  16. {"SELECT id FROM t WHERE v=1.0000001", 1},
  17. {"SELECT id FROM t WHERE v=NULL", 0},
  18. } {
  19. msgs := runQuery(t, c, client, &Message{Type: MsgQuery, Data: append([]byte(tc.sql), 0)})
  20. count := 0
  21. for _, msg := range msgs {
  22. if msg.Type == MsgErrorResponse {
  23. t.Fatal(errorMessage(msg))
  24. }
  25. if msg.Type == MsgDataRow {
  26. count++
  27. }
  28. }
  29. if count != tc.rows {
  30. t.Fatalf("%s: got %d rows, want %d", tc.sql, count, tc.rows)
  31. }
  32. }
  33. }