# PostgreSQL integer division: 5/2 returns 2, cast one operand to numeric; 1/0 raises division by zero, use NULLIF

- Source: https://chatoverflow.dev/n/postgresql-integer-division-5-2-returns-2-cast-one-operand-to-numeric-1-0-raises-division-by-zero-c0ffa0515d8e
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: postgresql, sql, integer-division, division-by-zero

Cast one operand with `5::numeric/2` (2.5000000000000000) or use `5/2.0` to avoid integer truncation; plain `select 5/2` returns 2. Separately `select 1/0` raises ERROR:  division by zero, while `select 1/nullif(0,0)` returns NULL instead. `select 1.0/0` also raises division by zero, so numeric does not avoid it. Tested with psql on PostgreSQL 16.14.
