EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

PostgreSQL CURRENT_TIME

Home » Data Science » Data Science Tutorials » PostgreSQL Tutorial » PostgreSQL CURRENT_TIME

PostgreSQL CURRENT_TIME

Introduction to PostgreSQL CURRENT_TIME

PostgreSQL provides a various function for manipulating time values. It is one of them which is used to get the current time of day. It returns the current time value of 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 the PostgreSQL CURRENT_TIME() function with PostgreSQL 8.4, PostgreSQL 9.0, PostgreSQL 9.1, PostgreSQL 9.2, PostgreSQL 9.3, and PostgreSQL 9.4, etc versions.

Syntax:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

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 defined, 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 which is 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.

Example:

Consider the following, which will return the current time in ‘HH:MM: SS.US+TZ’ format.

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 use the PostgreSQL CURRENT_TIME() function in table creation as well. We can give a default value to the column by using the PostgreSQL CURRENT_TIME() function. It will have different time values as per the execution time of the PostgreSQL CURRENT_TIME() 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 are using the PostgreSQL CURRENT_TIME() function for setting a default value the PostgreSQL CURRENT_TIME() function.

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 SQL statement as given above, joining will be as per the SQL query execution time.

Recommended Articles

This is a guide to PostgreSQL CURRENT_TIME. Here we discuss how PostgreSQL CURRENT_TIME() function work in PostgreSQL with respective examples. You may also have a look at the following articles to learn more –

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

PostgreSQL Course (2 Courses, 1 Project)

2 Online Courses

1 Hands-on Project

7+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

2 Shares
Share
Tweet
Share
Primary Sidebar
PostgreSQL Tutorial
  • Advanced
    • PostgreSQL Schema
    • Postgres List Schemas
    • PostgreSQL VARCHAR
    • Array in PostgreSQL
    • PostgreSQL DDL
    • PostgreSQL List Users
    • Postgres Default User
    • Postgres add user
    • PostgreSQL log_statement
    • PostgreSQL String Functions
    • PostgreSQL Compare Strings
    • PostgreSQL Text Search
    • PostgreSQL TEXT
    • PostgreSQL String Array
    • PostgreSQL Constraints
    • PostgreSQL UNIQUE Constraint
    • PostgreSQL INTERSECT
    • PostgreSQL Like
    • Cursors in PostgreSQL
    • PostgreSQL UNION ALL
    • Indexes in PostgreSQL
    • PostgreSQL Index Types
    • PostgreSQL REINDEX
    • PostgreSQL UNIQUE Index
    • PostgreSQL Clustered Index
    • PostgreSQL DROP INDEX
    • PostgreSQL DISTINCT
    • PostgreSQL FETCH
    • PostgreSQL RAISE EXCEPTION
    • PostgreSQL Auto Increment
    • Sequence in PostgreSQL
    • Wildcards in PostgreSQL
    • PostgreSQL Subquery
    • PostgreSQL Alias
    • PostgreSQL LIMIT
    • PostgreSQL Limit Offset
    • PostgreSQL LAG()
    • PostgreSQL Table
    • Postgres Show Tables
    • PostgreSQL Describe Table
    • PostgreSQL Lock Table
    • PostgreSQL ALTER TABLE
    • Postgres Rename Table
    • Postgres DROP Table
    • PostgreSQL Functions
    • PostgreSQL Math Functions
    • PostgreSQL Window Functions
    • Aggregate Functions in PostgreSQL
    • PostgreSQL Primary Key
    • Foreign Key in PostgreSQL
    • PostgreSQL Procedures
    • PostgreSQL Stored Procedures
    • PostgreSQL Views
    • PostgreSQL Materialized Views
    • Postgres Create View
    • PostgreSQL Triggers
    • PostgreSQL DROP TRIGGER
    • PostgreSQL Date Functions
    • PostgreSQL TO_DATE()
    • PostgreSQL Timestamp
    • PostgreSQL CURRENT_TIMESTAMP()
    • PostgreSQL Notify
    • PostgreSQL RANK()
    • PostgreSQL Select
    • PostgreSQL Average
    • PostgreSQL DATE_PART()
    • PostgreSQL EXECUTE
    • PostgreSQL COALESCE
    • PostgreSQL EXTRACT()
    • PostgreSQL Sort
    • PostgreSQL TO_CHAR
    • PostgreSQL Interval
    • PostgreSQL Number Types
    • PostgreSQL ROW_NUMBER
    • Alter Column in PostgreSQL
    • PostgreSQL Identity Column
    • PostgreSQL SPLIT_PART()
    • PostgreSQL CONCAT()
    • PostgreSQL replace
    • PostgreSQL TRIM()
    • PostgreSQL MAX
    • PostgreSQL DELETE
    • PostgreSQL Float
    • PostgreSQL OID
    • PostgreSQL log
    • PostgreSQL REGEXP_MATCHES()
    • PostgreSQL MD5 
    • PostgreSQL NOW()
    • PostgreSQL RANDOM
    • PostgreSQL round
    • PostgreSQL Trunc()
    • PostgreSQL TIME
    • PostgreSQL IS NULL
    • PostgreSQL CURRENT_TIME
    • PostgreSQL MOD()
    • Postgresql Count
    • PostgreSQL Datetime
    • PostgreSQL MIN()
    • PostgreSQL age()
    • PostgreSQL enum
    • PostgreSQL OR
    • PostgreSQL Wal
    • PostgreSQL NOT IN
    • PostgreSQL SET
    • PostgreSQL Current Date
    • PostgreSQL Compare Date
    • PostgreSQL SERIAL
    • PostgreSQL Database
    • PostgreSQL Clone Database
    • PostgreSQL Copy Database
    • PostgreSQL Restore Database
    • PostgreSQL DROP DATABASE
    • PostgreSQL ALTER DATABASE
    • Postgres DROP Database
    • Postgres Dump Database
    • PostgreSQL OFFSET
    • PostgreSQL GRANT
    • PostgreSQL COMMIT
    • PostgreSQL ROLLUP
    • PostgreSQL JSON
    • EXPLAIN ANALYZE in PostgreSQL
    • PostgreSQL Temporary Table
    • PostgreSQL cluster
    • PostgreSQL Replication
    • PostgreSQL Logical Replication
    • PostgreSQL flush privileges
    • PostgreSQL Tablespaces
    • CAST in PostgreSQL
    • PostgreSQL CTE
    • hstore in PostgreSQL
    • PostgreSQL DECODE()
    • PostgreSQL Vacuum
    • PostgreSQL EXCLUDE
    • Postgres Change Password
    • Postgres Delete Cascade
    • PostgreSQL EXCEPT
    • PostgreSQL Roles
    • PostgreSQL Link
    • PostgreSQL Partition
    • PostgreSQL column does not exist
    • PostgreSQL Log Queries
    • PostgreSQL escape single quote
    • PostgreSQL Query Optimization
    • PostgreSQL Character Varying
    • PostgreSQL Transaction
    • PostgreSQL Extensions
    • PostgreSQL Import CSV
    • PostgreSQL Client
    • PostgreSQL caching
    • PostgreSQL JDBC Driver
    • PostgreSQL Interview Questions
  • Basic
    • What is PostgreSQL
    • PostgreSQL Features
    • How to Install PostgreSQL
    • PostgreSQL Versions
    • PostgreSQL Architecture
    • PostgreSQL GUI
    • PostgreSQL Variables
    • PostgreSQL Data Types
    • PostgreSQL NOT NULL
    • PostgreSQL Integer
    • PostgreSQL Boolean
    • PostgreSQL NULLIF
    • PostgreSQL Administration
    • PostgreSQL Commands
    • PostgreSQL Operators
    • PostgreSQL IN Operator
  • Control Statement
    • PostgreSQL IF Statement
    • PostgreSQL if else
    • PostgreSQL CASE Statement
    • PostgreSQL LOOP
    • PostgreSQL For Loop
    • PostgreSQL While Loop
  • Joins
    • Joins in PostgreSQL
    • PostgreSQL Inner Join
    • PostgreSQL Outer Join
    • LEFT OUTER JOIN in PostgreSQL
    • PostgreSQL FULL OUTER JOIN
    • PostgreSQL LEFT JOIN
    • PostgreSQL Full Join
    • PostgreSQL Cross Join
    • PostgreSQL NATURAL JOIN
    • PostgreSQL UPDATE JOIN
  • Queries
    • PostgreSQL Queries
    • PostgreSQL WHERE Clause
    • PostgreSQL WITH Clause
    • PostgreSQL ORDER BY
    • PostgreSQL ORDER BY Random
    • PostgreSQL GROUP BY
    • PostgreSQL group_concat
    • PostgreSQL HAVING
    • PostgreSQL Recursive Query
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • 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

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

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

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

EDUCBA

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

Forgot Password?

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

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

Special Offer - PostgreSQL Course (2 Courses, 1 Project) Learn More