EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials PostgreSQL Tutorial PostgreSQL CURRENT_TIME
 

PostgreSQL CURRENT_TIME

Updated May 12, 2023

PostgreSQL CURRENT_TIME

 

 

Introduction to PostgreSQL CURRENT_TIME

PostgreSQL provides various functions for manipulating time values. It is one of them used to get the current time of day. It returns the current time value of the day with the time zone in which it is called. Even if the CURRENT_TIME() is a function but while using the CURRENT_TIME() function, it is not necessary to define the parentheses () if we are not specifying the precision parameter. The returned time format of the PostgreSQL CURRENT_TIME() function is a ‘HH:MM: SS.US+TZ.’ We can use this function with PostgreSQL 8.4, PostgreSQL 9.0, PostgreSQL 9.1, PostgreSQL 9.2, PostgreSQL 9.3, and PostgreSQL 9.4, etc. versions.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax:

Given below is the syntax:

current_time( [ precision ] )

Explanation:

  • precision: It is an optional parameter. The value defined is used as fractional seconds precision. If the precision is not specified, then the PostgreSQL CURRENT_TIME() function returns the day’s current time with the full available precision.

How PostgreSQL CURRENT_TIME() Function work in PostgreSQL?

  • It is used to get the current time of day with the time zone.
  • The returned time format of the PostgreSQL CURRENT_TIME() function is a ‘HH:MM:SS.US+TZ.’
  • It takes precision as an optional parameter used as fractional seconds precision. If the precision is not defined, then the PostgreSQL CURRENT_TIME() function returns the day’s current time with the full available precision.

Code:

SELECT current_time AS current_day_time;

Output:

PostgreSQL CURRENT_TIME 1

Examples of PostgreSQL CURRENT_TIME

Given below are the examples with and without precision defined:

Example #1

Code:

SELECT current_time(1) AS current_day_time_prec_1;

Output:

PostgreSQL CURRENT_TIME 2

Example #2

Code:

SELECT current_time(2) AS current_day_time_prec_2;

Output:

AS current_day_time_prec_2;

Example #3

Code:

SELECT current_time(3) AS current_day_time_prec_3;

Output:

AS current_day_time_prec_3;

Example #4

We can also use the PostgreSQL CURRENT_TIME() function in table creation. We can give a default value to the column. It will have different time values as per the execution time of this function.

Consider the following example where we will create a table named ‘Employee,’ and this table will have a column ‘creation_time’ with data type as TIME. The column ‘creation_time’ will have a default value set to the current time as we use the PostgreSQL CURRENT_TIME() function to set a default value for the PostgreSQL CURRENT_TIME() part.

Consider the following CREATE TABLE statement, which will create a table named ‘Employee.’

Code:

CREATE TABLE Employee(
Employee_id serial PRIMARY KEY,
Employee_name varchar(255) NOT NULL,
creation_time TIME DEFAULT CURRENT_TIME
);

Now, we will insert a row into the Employee table by using the INSERT INTO statement as follows:

Code:

INSERT INTO Employee(Employee_name)
VALUES('Jacob Petter');

In the above INSERT INTO statement, we have not specified the creation time; hence the, PostgreSQL sets the default value as the current time.

Illustrate the result of the Employee table by using the following SQL statement and a snapshot.

Code:

SELECT * FROM Employee;

Output:

PostgreSQL CURRENT_TIME 5

Now, we will again insert a row into the Employee table by using the INSERT INTO statement as follows:

Code:

INSERT INTO Employee(Employee_name)
VALUES('David Bravo');

Illustrate the result of the Employee table by using the following SQL statement and a snapshot.

Code:

SELECT * FROM Employee;

Output:

SELECT * FROM Employee;

As per the SQL query execution time, the Employee table will have different time values inserted in the ‘creation_time’ column. If someone is joining a company in the morning and someone is joining in the afternoon, and we execute the insert into the SQL statement as given above, joining will be as per the SQL query execution time.

Recommended Articles

We hope that this EDUCBA information on “PostgreSQL CURRENT_TIME” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. PostgreSQL UPDATE JOIN
  2. Variables PostgreSQL
  3. PostgreSQL FULL OUTER JOIN
  4. PostgreSQL While Loop

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW