PostgreSQL: Mathematical Functions and Operators

I kind of skipped over the functions/operators section of the PostgreSQL documentation when reading it. I want to review the sections that I think would be useful to me.

Date Created:
1 17

References



Notes


Description

Operator

Addition

numeric_type + numeric_type -> numeric_type

Unary Plus

+ numeric_type -> numeric_type

Subtraction

numeric_type - numeric_type -> numeric_type

Negation

- numeric_type -> numeric_type

Multiplication

numeric_type * numeric_type -> numeric_type

Division

numeric_type / numeric_type -> numeric_type

Modulo

numeric_type % numeric_type -> numeric_type

Exponentiation

numeric ^ numeric -> numeric

Square Root

|/ double precision -> double precision

Cube Root

||/ double precision -> double precision

Absolute Value

@ numeric_type -> numeric_type

Bitwise AND

integral_type & integral_type -> integral_type

Bitwise OR

integral_type | integral_type -> integral_type

Bitwise Exclusive OR

integral_type # integral_type -> integral_type

Bitwise NOT

~ integral_type -> integral_type

Bitwise Shift Left

integral_type << integer -> inregral_type

Bitwise Shift Right

integral_type >> integer -> integral_type


Description

Function

Absolute value

abs(numeric_type) -> numeric_type

Cube Root

cbrt(double precision) -> double precision

Nearest Integer Greater than or Equal to Argument

ceil(numeric) -> double precision

Convert Radians to Degrees

degrees(double precision) -> double precision

Integer Quotient of y/x (truncates towards 0)

div(y numeric, x numeric) -> numeric

Exponential

exp(numeric) -> numeric

Factorial

factorial(bigint) -> numeric

Nearest Integer Less Than or Equal to Argument

floor(numeric) -> numeric

Greatest Common Divisor

gcd(numeric_type, numeric_type) -> numeric_type

Least Common Multiple

lcm(numeric_type,numeric_type) -> numeric_type

Natural Logarithm

ln(numeric) -> numeric

Logarithm of x to base b

log(b numeric, x numeric) -> numeric

a raised to the power of b

power(a numeric, b numeric) -> numeric

Convert degrees to radians

radians(double precision) -> double precision

Round to nearest integer

round(numeric) -> numeric

Truncates v to s decimal places

trunc(v numeric, s integer) -> numeric

The random() and random_normal() functions below use a deterministic pseudo-random number generator.

Random Functions

Comments

You have to be logged in to add a comment

User Comments

Insert Math Markup

ESC
About Inserting Math Content
Display Style:

Embed News Content

ESC
About Embedding News Content

Embed Youtube Video

ESC
Embedding Youtube Videos

Embed TikTok Video

ESC
Embedding TikTok Videos

Embed X Post

ESC
Embedding X Posts

Embed Instagram Post

ESC
Embedding Instagram Posts

Insert Details Element

ESC

Example Output:

Summary Title
You will be able to insert content here after confirming the title of the <details> element.

Insert Table

ESC
Customization
Align:
Preview:

Insert Horizontal Rule

#000000

Preview:


View Content At Different Sizes

ESC

Edit Style of Block Nodes

ESC

Edit the background color, default text color, margin, padding, and border of block nodes. Editable block nodes include paragraphs, headers, and lists.

#ffffff
#000000

Edit Selected Cells

Change the background color, vertical align, and borders of the cells in the current selection.

#ffffff
Vertical Align:
Border
#000000
Border Style:

Edit Table

ESC
Customization:
Align:

Upload Lexical State

ESC

Upload a .lexical file. If the file type matches the type of the current editor, then a preview will be shown below the file input.

Upload 3D Object

ESC

Upload Jupyter Notebook

ESC

Upload a Jupyter notebook and embed the resulting HTML in the text editor.

Insert Custom HTML

ESC

Edit Image Background Color

ESC
#ffffff

Insert Columns Layout

ESC
Column Type:

Select Code Language

ESC
Select Coding Language

Insert Chart

ESC

Use the search box below

Upload Previous Version of Article State

ESC