EDUCBA

EDUCBA

MENUMENU
  • Explore
    • Lifetime Membership
    • All in One Bundles
    • 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.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

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
ADVERTISEMENT
All in One Excel VBA Bundle
500+ Hours of HD Videos
15 Learning Paths
120+ Courses
Verifiable Certificate of Completion
Lifetime Access
ADVERTISEMENT
Financial Analyst Masters Training Program
2000+ Hours of HD Videos
43 Learning Paths
550+ Courses
Verifiable Certificate of Completion
Lifetime Access
ADVERTISEMENT
All in One Data Science Bundle
2000+ Hour of HD Videos
80 Learning Paths
400+ Courses
Verifiable Certificate of Completion
Lifetime Access
ADVERTISEMENT
All in One Software Development Bundle
5000+ Hours of HD Videos
149 Learning Paths
1050+ Courses
Verifiable Certificate of Completion
Lifetime Access
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - 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

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

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

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

Forgot Password?

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Extended Cyber Monday Price Drop! All in One Universal Bundle (3700+ Courses) @ 🎁 90% OFF - Ends in ENROLL NOW