EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials PostgreSQL Tutorial PostgreSQL CURRENT_TIMESTAMP()
Secondary Sidebar
PostgreSQL Tutorial
  • Basic
    • What is PostgreSQL
    • PostgreSQL Features
    • How to Install PostgreSQL
    • PostgreSQL Versions
    • PostgreSQL Architecture
    • PostgreSQL GUI
    • Postgres Command-Line
    • PostgreSQL Variables
    • PostgreSQL Data Types
    • PostgreSQL NOT NULL
    • PostgreSQL Integer
    • PostgreSQL Boolean
    • PostgreSQL BIGINT
    • PostgreSQL NULLIF
    • PostgreSQL Administration
    • PostgreSQL Commands
    • PostgreSQL Operators
    • PostgreSQL IN Operator
    • Postgres like query
    • PostgreSQL encode
    • PostgreSQL Cheat Sheet
    • PostgreSQL List Databases
    • PostgreSQL Rename Database
  • 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 INSERT INTO
    • PostgreSQL WHERE Clause
    • PostgreSQL WITH Clause
    • PostgreSQL ORDER BY
    • PostgreSQL ORDER BY Random
    • PostgreSQL ORDER BY DESC
    • PostgreSQL GROUP BY
    • PostgreSQL group_concat
    • PostgreSQL HAVING
    • PostgreSQL Recursive Query
  • Advanced
    • PostgreSQL Schema
    • Postgres List Schemas
    • PostgreSQL Drop Schema
    • PostgreSQL VARCHAR
    • Array in PostgreSQL
    • PostgreSQL DDL
    • PostgreSQL List Users
    • Postgres Default User
    • Postgres add user
    • PostgreSQL User Password
    • PostgreSQL log_statement
    • PostgreSQL repository
    • PostgreSQL shared_buffer
    • PostgreSQL String Functions
    • PostgreSQL Compare Strings
    • PostgreSQL Text Search
    • PostgreSQL TEXT
    • PostgreSQL String Array
    • PostgreSQL where in array
    • PostgreSQL Constraints
    • PostgreSQL UNIQUE Constraint
    • PostgreSQL CHECK 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
    • PostgreSQL List Tables
    • PostgreSQL TRUNCATE TABLE
    • PostgreSQL Table Partitioning
    • 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 datediff
    • PostgreSQL Timestamp
    • PostgreSQL CURRENT_TIMESTAMP()
    • PostgreSQL Notify
    • PostgreSQL LENGTH()
    • PostgreSQL blob
    • PostgreSQL Median
    • PostgreSQL kill query
    • PostgreSQL Formatter
    • 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 UUID
    • PostgreSQL Merge
    • PostgreSQL Database
    • PostgreSQL Clone Database
    • PostgreSQL Copy Database
    • PostgreSQL Show Databases
    • 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 Show Tables
    • PostgreSQL cluster
    • PostgreSQL Replication
    • PostgreSQL Logical Replication
    • PostgreSQL flush privileges
    • PostgreSQL Tablespaces
    • CAST in PostgreSQL
    • PostgreSQL CTE
    • hstore in PostgreSQL
    • PostgreSQL Encryption
    • 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 Incremental Backup
    • PostgreSQL JSON vs JSONNB
    • PostgreSQL JDBC Driver
    • PostgreSQL Interview Questions

PostgreSQL CURRENT_TIMESTAMP()

By Sohel SayyadSohel Sayyad

PostgreSQL CURRENT_TIMESTAMP()

Introduction to PostgreSQL CURRENT_TIMESTAMP()

PostgreSQL CURRENT_TIMESTAMP() is used to return the current date and time with time zone, it will display the time when our transaction starts. This is the PostgreSQL SQL standard function which was used to return the values based on the start time of the current transactions in PostgreSQL. Current timestamp and transaction timestamp functions are equivalent to each other, but the current timestamp will return the current date and time and transaction timestamp will return transaction start time. Current timestamp, transaction timestamp and now function in PostgreSQL doing exactly the same but the current timestamp is syntactical oddity function.

Syntax

Below is the syntax of the current_timestamp function in PostgreSQL.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Current_timestamp;

OR

Current_timestamp (<Precision>)

Parameter Description

Below is the parameter description syntax of the current timestamp function in PostgreSQL.

Current timestamp: Current timestamp in PostgreSQL will return the current date and time. The current timestamp is the SQL-Standard function in PostgreSQL used to return values based on the start time of the current transaction.

Precision: It is an optional parameter that was used in the current timestamp function in PostgreSQL.The precision is specified that number of digits in fractional second’s precision in the second filed of result in PostgreSQL. If we not used precision argument in current timestamp function it will return timestamp with time zone this includes include the full fractional second’s precision in PostgreSQL.

How does PostgreSQL CURRENT_TIMESTAMP() function work?

Below is the working of the current timestamp in PostgreSQL:

  • The current timestamp is used to return the current date and time with the time zone in PostgreSQL.
  • We can use the precision parameter with the current timestamp function in PostgreSQL.
  • In PostgreSQL internally current timestamp will work as now function in PostgreSQL. The current timestamp and now function is similar work in PostgreSQL.
  • Transaction timestamp and the current timestamp is equivalent to each other in PostgreSQL. But transaction timestamp will reflect the same which was return by the function.

Examples to Implement PostgreSQL CURRENT_TIMESTAMP()

The below example shows that now, current timestamp and transaction timestamp function is work similar to each other:

Example #1

Code:

SELECT CURRENT_TIMESTAMP;
SELECT now();
SELECT transaction_timestamp();

Output:

PostgreSQL CURRENT_TIMESTAMP()1

Explanation: The above example shows the time and timestamp of all three functions working is the same. The current timestamp is basically used as the default timestamp value of a column in PostgreSQL. The current timestamp and the current time are to deliver the values with the time zone in PostgreSQL. The start time of the current statement is the time of the latest command received from the client. The current timestamp is very useful and important in PostgreSQL to return the date and timestamp with the time zone. We can provide the default value of the current timestamp to a column in PostgreSQL by using the default keyword. We can provide default current timestamp value to the column at the time of table creation. After specifying the default value as the current timestamp, then we have no need to insert current timestamp value in every insert statement. It will automatically take the current date and time in the column which has defined default current timestamp in PostgreSQL. The current timestamp function in PostgreSQL will return the current date in the following format are as follows.

‘YYYY-MM-DD HH:MM: SS.US+TZ’

Example #2

Below example shows the format of current timestamp function in PostgreSQL:

Code:

SELECT CURRENT_TIMESTAMP;

Output:

PostgreSQL CURRENT_TIMESTAMP()2

Explanation: In the above example the format of the current timestamp is as below.

  • YYYY – It is defined as the year in four-digit.
  • MM – It defines the month in two digits. The range is 01 to 12.
  • DD – It is defined as today’s date in two digits. The range is 01 to 31.
  • HH – It is defined as the current hour in two digits. The range is 00 to 23.
  • MM – It is defined as the current minute in two digits. The range is 00 to 59.
  • SS – It is defined as the current second in two digits. The range is 00 to 59.
  • TZ – It is defined as the time zone in the current timestamp function.
  • We have not need to use () in the current timestamp function when we have not used the precision parameter.

Example #3

If we have used () without precision parameter it will show a syntax error. The below example shows that we have no need to use () when we have not used the precision parameter:

Code:

SELECT CURRENT_TIMESTAMP;

Output:

PostgreSQL CURRENT_TIMESTAMP()3

Example #4

Current timestamp with precision value:

 In the below example we have used precision value as 5 with the current timestamp. We have used five fractional seconds to define the current timestamp.

Code:

SELECT CURRENT_TIMESTAMP (5);

Output:

PostgreSQL CURRENT_TIMESTAMP()4

Example #5

Current timestamp without using precision value:

In the below example we have not used precision value with the current timestamp. We not used (), because we have not defined precision value in the below example.

Code:

SELECT CURRENT_TIMESTAMP;

Output:

precision value

Example #6

Use current timestamp in the column as the default value:

In the below example we have used the current timestamp as default value in the student table. In the below example we have created default current timestamp on admission_date column.

Code:

CREATE TABLE student (stud_id serial PRIMARY KEY, stud_address varchar(255) NOT NULL, stud_name varchar(255) NOT NULL, admission_date TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP);

Output:

default current timestamp

Example #7

After creating the student table we have no need to insert value in the column name as admission_date. It will take the automatic value as the current timestamp at the time of insertion are as follows.

Code:

INSERT INTO STUDENT (stud_id, stud_address, stud_name) VALUES (1, 'Pune', 'ABC');
INSERT INTO STUDENT (stud_id, stud_address, stud_name) VALUES (2, 'Mumbai', 'PQR');
select * from STUDENT;

Output:

automatic value

Recommended Articles

This is a guide to PostgreSQL CURRENT_TIMESTAMP(). Here we discuss introduction to PostgreSQL CURRENT_TIMESTAMP(), syntax for it, how does it work and examples. You can also go through our other related articles to learn more –

  1. PostgreSQL GRANT
  2. PostgreSQL Trunc()
  3. PostgreSQL FULL OUTER JOIN
  4. PostgreSQL replace
Popular Course in this category
PostgreSQL Course (2 Courses, 1 Project)
  2 Online Courses |  1 Hands-on Project |  7+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • 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

ISO 10004:2018 & ISO 9001:2015 Certified

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

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

Let’s Get Started

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

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?

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

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