[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4656
  • Last Modified:

no sysdate in postgresql

HI
I noticed that there is no sysdate in postresql
i want to execute following syntax: sysdate-2
i use current_timestamp but receive an error message below

DBD:: PgPP::st execute failed:ERROR: operator does not exist:
timestamp with time zone - integer at char 111
0
tankergoblin
Asked:
tankergoblin
1 Solution
 
psychic_zeroCommented:
Try this:

SELECT now() AS timestamp;

Also can you give your SQL statement and what -2 supposed to do?
0
 
RazvanStefanescuCommented:
Hello,
I think you may use the following code.

BR,
Razvan
now() - interval '2 days'

Open in new window

0
 
tankergoblinAuthor Commented:
can i use integer?
now()- integer '2';
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
tankergoblinAuthor Commented:
what is the difference btw interval and integer
0
 
RazvanStefanescuCommented:
Hello,
You can use integer. The "interval way" you can use constructions like "interval '1 day' - interval '1 hour'", which is equivalent to "interval '23:00'". It is just easier to read.
0
 
RazvanStefanescuCommented:
Hello,
For more info about date/time operations:

http://developer.postgresql.org/pgdocs/postgres/functions-datetime.html
0
 
tankergoblinAuthor Commented:
so that mean there is no difference between integer and interval?
0
 
earth man2Commented:
sysdate is an Oracle extension to the ANSI standard, use current_date.
select current_date - 2;
0
 
RazvanStefanescuCommented:
Hello,
If you work with dates, you can use integers. If you work with timestamps, interval is better.
You can see below an example where interval gives you some interesting result:
        '2001-02-02'::TIMESTAMP + '1 month'::INTERVAL = '2001-03-02'::TIMESTAMP
        '2001-02-02'::TIMESTAMP + '31 days'::INTERVAL = '2001-03-05'::TIMESTAMP
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now