↑↓ select ↵ open ⌫ change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Functions / Mathematical Functions And Operators

Truncates to integer (towards zero)

Reading PG 18current·documented in 27 of 27 versions, 7.1 to 20

Signatures & examples

trunc ( numeric ) → numeric
Truncates to integer (towards zero)
trunc(42.8) → 42
trunc(-42.8) → -42
trunc ( double precision ) → double precision
Truncates to integer (towards zero)
trunc(42.8) → 42
trunc(-42.8) → -42
trunc ( v numeric, s integer ) → numeric
Truncates v to s decimal places
trunc(42.4382, 2) → 42.43
trunc ( macaddr ) → macaddr
Sets the last 3 bytes of the address to zero. The remaining prefix can be associated with a particular manufacturer (using data not included in PostgreSQL).
trunc(macaddr '12:34:56:78:90:ab') → 12:34:56:00:00:00
trunc ( macaddr8 ) → macaddr8
Sets the last 5 bytes of the address to zero. The remaining prefix can be associated with a particular manufacturer (using data not included in PostgreSQL).
trunc(macaddr8 '12:34:56:78:90:ab:cd:ef') → 12:34:56:00:00:00:00:00
Version history 4
  1. 12 → 13 changed
  2. 9.6 → 10 changed
  3. 8.0 → 8.1 changed
  4. 7.2 → 7.3 changed

Definition snapshot: b7bd9cda · English manual source