PostgreSQL LOCALTIME Function
Summary: in this tutorial, you will learn how to use the PostgreSQLLOCALTIME function to return the current time at which the current transaction starts.
Introduction to PostgreSQL LOCALTIME function
TheLOCALTIME() function returns the current time at which the current transaction starts.
Here’s the basic syntax of theLOCALTIME function:
LOCALTIME(precision)TheLOCALTIME function takes one optional argument:
1)precision
Theprecision argument specifies fractional seconds precision of the second field.
If you omit theprecision argument, it defaults to 6.
TheLOCALTIME function returns aTIME value that represents the time at which the current transaction starts.
Note that theLOCATIME function returns aTIME without time zone whereas theCURRENT_TIME function returns aTIME with the timezone.
PostgreSQL LOCALTIME function examples
Let’s take some examples of using theLOCALTIME function.
1) Basic PostgreSQL LOCALTIME function example
The following example uses theLOCALTIME function to get the time of the current transaction:
SELECT LOCALTIME;Output:
localtime----------------- 16:37:59.950622(1 row)2) Using the PostgreSQL LOCALTIME function with fractional seconds precision
The following example uses theLOCALTIME(2) function to get the time with a specified fractional seconds precision:
SELECT LOCALTIME(2);Output:
localtime------------- 16:38:07.97(1 row)Summary
- Use the PostgreSQL
LOCALTIMEfunction to get the time at which the current transaction starts.
Last updated on