Skip to content

Latest commit

 

History

History
43 lines (40 loc) · 10.1 KB

postgres.md

File metadata and controls

43 lines (40 loc) · 10.1 KB

Network Address Functions

https://www.postgresql.org/docs/16/functions-net.html

Implemented Function Return Type Description Example Result
abbrev(inet) text abbreviated display format as text abbrev(inet '10.1.0.0/16') 10.1.0.0/16
abbrev(cidr) text abbreviated display format as text abbrev(cidr '10.1.0.0/16') 10.1/16
✅︎ broadcast(inet) inet broadcast address for network broadcast('192.168.1.5/24') 192.168.1.255/24
✅︎ family(inet) int extract family of address; 4 for IPv4, 6 for IPv6 family('::1') 6
✅︎ host(inet) text extract IP address as text host('192.168.1.5/24') 192.168.1.5
✅︎ hostmask(inet) inet construct host mask for network hostmask('192.168.23.20/30') 0.0.0.3
✅︎ masklen(inet) int extract netmask length masklen('192.168.1.5/24') 24
✅︎ netmask(inet) inet construct netmask for network netmask('192.168.1.5/24') 255.255.255.0
✅︎ network(inet) cidr extract network part of address network('192.168.1.5/24') 192.168.1.0/24
✅︎ set_masklen(inet, int) inet set netmask length for inet value set_masklen('192.168.1.5/24', 16) 192.168.1.5/16
✅︎ set_masklen(cidr, int) cidr set netmask length for cidr value set_masklen('192.168.1.0/24'::cidr, 16) 192.168.0.0/16
text(inet) text extract IP address and netmask length as text text(inet '192.168.1.5') 192.168.1.5/32
✅︎ inet_same_family(inet, inet) boolean are the addresses from the same family? inet_same_family('192.168.1.5/24', '::1') false
✅︎ inet_merge(inet, inet) cidr the smallest network which includes both of the given networks inet_merge('192.168.1.5/24', '192.168.2.5/24')

Mathematics Functions

https://www.postgresql.org/docs/16/functions-math.html

Implemented Function Description Example
✅︎ ceiling ( numeric ) → numeric Nearest integer greater than or equal to argument (same as ceil) ceiling(95.3) → 96
✅︎ div ( y numeric, x numeric ) → numeric Integer quotient of y/x (truncates towards zero) div(9, 4) → 2
✅︎ erf ( double precision ) → double precision Error function erf(1.0) → 0.8427007929497149
erfc ( double precision ) → double precision Complementary error function (1 - erf(x), without loss of precision for large inputs) erfc(1.0) → 0.15729920705028513
min_scale ( numeric ) → integer Minimum scale (number of fractional decimal digits) needed to represent the supplied value precisely min_scale(8.4100) → 2
mod ( y numeric_type, x numeric_type ) → numeric_type Remainder of y/x; available for smallint, integer, bigint, and numeric mod(9, 4) → 1
scale ( numeric ) → integer Scale of the argument (the number of decimal digits in the fractional part) scale(8.4100) → 4
sign ( numeric ) → numeric Sign of the argument (-1, 0, or +1) sign(-8.4) → -1
trim_scale ( numeric ) → numeric Reduces the value's scale (number of fractional decimal digits) by removing trailing zeroes trim_scale(8.4100) → 8.41
width_bucket ( operand numeric, low numeric, high numeric, count integer ) → integer Returns the number of the bucket in which operand falls in a histogram having count equal-width buckets spanning the range low to high. Returns 0 or count+1 for an input outside that range. width_bucket(5.35, 0.024, 10.06, 5) → 3
random_normal ( [ mean double precision [, stddev double precision ]] ) → double precision Returns a random value from the normal distribution with the given parameters; mean defaults to 0.0 and stddev defaults to 1.0 random_normal(0.0, 1.0) → 0.051285419
acosd ( double precision ) → double precision Inverse cosine, result in degrees acosd(0.5) → 60
asind ( double precision ) → double precision Inverse sine, result in degrees asind(0.5) → 30
atand ( double precision ) → double precision Inverse tangent, result in degrees atand(1) → 45
cosd ( double precision ) → double precision Cosine, argument in degrees cosd(60) → 0.5
cotd ( double precision ) → double precision Cotangent, argument in degrees cotd(45) → 1
sind ( double precision ) → double precision Sine, argument in degrees sind(30) → 0.5
tand ( double precision ) → double precision Tangent, argument in degrees tand(45) → 1