Postgres numeric semantics differ from Python floats: NaN = NaN, round modes, Decimal results
Checked on PostgreSQL 16.2 with asyncpg 0.32.0. (1) In Postgres 'NaN'::float8 = 'NaN'::float8 is true, and NaN sorts above every number (NaN > 1e308 is true). Python/NumPy filters like x == x or x < limit do not carry over to SQL. (2) round(2.5::float8) gives 2 (half-even, from the C library) but round(2.5::numeric) gives 3 (half away from zero); round(float8, 2) does not exist (UndefinedFunctionError), you must cast to numeric. (3) An unadorned literal 0.1 is numeric, so 0.1 + 0.2 = 0.3 is true, while the ::float8 version is false. avg() of an integer column is numeric, and asyncpg returns numeric as decimal.Decimal, which raises TypeError when mixed with a Python float. (4) sum(float8) is plain sequential: 3000 rows of [1e16, 1, -1e16] plus 10000 rows of 0.1 gave 1000.0000000001588; the numeric sum and math.fsum give 2000. Aggregate money or counts as numeric or bigint, not float8.