Posts

Showing posts from October, 2020

PostgreSQL - DATE/TIME Functions and Operators

Image
  We had discussed about the Date/Time data types in the chapter   Data Types . Now, let us see the Date/Time operators and Functions. The following table lists the behaviors of the basic arithmetic operators − The following is the list of all important Date and Time related functions available. AGE(timestamp, timestamp), AGE(timestamp) Example of the function AGE(timestamp, timestamp) is − testdb =# SELECT AGE ( timestamp '2001-04-10' , timestamp '1957-06-13' ); The above given PostgreSQL statement will produce the following result − age ------------------------- 43 years 9 mons 27 days Example of the function AGE(timestamp) is − testdb =# select age ( timestamp '1957-06-13' ); The above given PostgreSQL statement will produce the following result − age -------------------------- 55 years 10 mons 22 days CURRENT DATE/TIME() PostgreSQL provides a number of functions that return values related to the current date and time. Foll

PostgreSQL - String Function

PostgreSQL string functions are used primarily for string manipulation. The following table details the important string functions − ASCII(str) Returns the numeric value of the leftmost character of the string str. Returns 0 if str is an empty string. Returns NULL if str is NULL. ASCII() works for characters with numeric values from 0 to 255. testdb=# SELECT ASCII('2'); +---------------------------------------------------------+ | ASCII('2') | +---------------------------------------------------------+ | 50 | +---------------------------------------------------------+ 1 row in set (0.00 sec) testdb=# SELECT ASCII('dx'); +---------------------------------------------------------+ | ASCII('dx') | +---------------------------------------------------------+ | 100 |

PostgreSQL - Numeric Function

  PostgreSQL numeric functions are used primarily for numeric manipulation and/or mathematical calculations. The following table details the numeric functions − ABS(X) The ABS() function returns the absolute value of X. Consider the following example − testdb =# SELECT ABS ( 2 ); +---------------------------------------------------------+ | ABS ( 2 ) | +---------------------------------------------------------+ | 2 | +---------------------------------------------------------+ 1 row in set ( 0.00 sec ) testdb =# SELECT ABS (- 2 ); +---------------------------------------------------------+ | ABS ( 2 ) | +---------------------------------------------------------+ | 2 | +---------------------------------------------------------+ 1 row in set ( 0.00 sec )