Arithmetic division operator /

Last updated: 2026-11-04

Arithmetic division operator /

The division operator / behaves differently depending on operand types: integer divided by integer performs integer division truncated toward zero, while numeric division keeps the fractional part. Dividing by zero raises an error for both. A NULL operand yields a NULL result.

Kindoperator
Example LanguageSQL

📝 Syntax

a / b

Precedence: `/` shares a level with `*` and `%` and is left-associative (`10 / 4 * 2` is 4 — divide first). Type determines precision: `total::int / n` truncates, while `total / n` on numeric keeps decimals. Dividing by zero aborts the statement rather than returning NULL, an important difference from MySQL.

⚙️ Parameters

aThe dividend; NULL if NULL, and 0 when the divisor is non-zero.
bThe divisor; NULL if NULL, and an error "division by zero" when 0.

Returns:Integer division returns integer truncated toward zero; numeric division returns numeric; dividing by zero raises an error.

▶ Example

Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.

Output:

SELECT id, total / n AS numeric_div, total::int / n AS int_div FROM t_div ORDER BY id
id |        numeric_div | int_div
---+--------------------+--------
 1 | 2.5000000000000000 |       2
 2 |               NULL |    NULL
(2 rows)

SELECT total / n IS NULL AS null_is_absent FROM t_div WHERE id = 2
null_is_absent
--------------
true          
(1 row)

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QDoes integer division lose precision?
AYes. 10 / 4 is 2 with the fraction truncated. Write 10.0 / 4 or total::numeric / n to get 2.5.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏