Skip to content

ToField for negative numbers should be parenthesized #143

Description

@ChickenProp

Postgresql parses - <num> :: <type> as - (<num> :: <type>). That can cause problems when trying to reference a type's minimum value:

> select -2147483648 :: int4;
ERROR:  integer out of range
> select (-2147483648) :: int4;
    int4     
-------------
 -2147483648

In the context of postgresql-simple, we can get problems if we try to do e.g.

execute conn "INSERT INTO foo (col) VALUES (?::int4)" (Only someInt)
query conn "SELECT * FROM ?" (Values ["int4"] [Only someInt])

I think postgres has symmetric ranges for non-integer numbers, but since those can get cast to ints, it can still make a difference whether they're parenthesized:

> select -2147483648.2 :: int4;
ERROR:  integer out of range
> select (-2147483648.2) :: int4;
    int4     
-------------
 -2147483648
(1 row)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions