Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres: Timestamp bigger than now

I try to select all records of a table (Postgres DB) with the following sql:

SELECT * FROM 'tablename' WHERE 'myTimestampRow' >= now()

There's allways an error message, telling me that there's an 'invalid input syntax for type timestamp with time zone: "myTimestampRow"'.

What's wrong with the above query?

like image 248
Basil Avatar asked Feb 13 '10 11:02

Basil


People also ask

What is current timestamp in PostgreSQL?

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.

Can you compare dates in PostgreSQL?

PostgreSQL compare date is used to compare date between two different dates, which we have used as an input. We can compare the date by using where and between clauses; we can also compare the date using the date_trunc function in PostgreSQL.

How does Postgres calculate time difference?

To calculate the difference between the timestamps in PostgreSQL, simply subtract the start timestamp from the end timestamp. Here, it would be arrival - departure . The difference will be of the type interval , which means you'll see it in days, hours, minutes, and seconds.

How do I get the current time in PostgreSQL?

You can use the PostgreSQL Now() function to display the current date and time of the timezone (default or user-defined) without any timestamp. You can use the “timestamp” keyword along with the Now() function.


2 Answers

Lose the single-quotes:

SELECT * FROM tablename WHERE myTimestampRow >= now()

You can optionally double-quote column- and table-names, but no single-quotes; they will be interpreted as characters/strings.

like image 61
mechanical_meat Avatar answered Oct 18 '22 20:10

mechanical_meat


You have

SELECT * FORM

instead of

SELECT * FROM

but that might be a typo in the question. I think your problem is the quoting of the columns, it should read either

SELECT * FROM table WHERE timestampRow >= now();

(no quotes) or

SELECT * FROM "table" WHERE "timestampRow" >= now();
like image 22
Vinko Vrsalovic Avatar answered Oct 18 '22 20:10

Vinko Vrsalovic