difference between current_timestamp and now() in quotes

Started by Grzegorz Jaśkiewiczabout 17 years ago13 messagesgeneral
Jump to latest
#1Grzegorz Jaśkiewicz
gryzman@gmail.com

test2=# create table dupa(a timestamp, b serial);
NOTICE: CREATE TABLE will create implicit sequence "dupa_b_seq" for
serial column "dupa.b"
CREATE TABLE

test2=# insert into dupa(a) select current_timestamp from
generate_series(1,100);
INSERT 0 100

test2=# insert into dupa(a) select 'current_timestamp' from
generate_series(1,100);
ERROR: date/time value "current" is no longer supported
LINE 1: insert into dupa(a) select 'current_timestamp' from generate...
^
test2=# insert into dupa(a) select 'now()' from generate_series(1,100);
INSERT 0 100

Any ideas why the difference ?

--
GJ

In reply to: Grzegorz Jaśkiewicz (#1)
Re: difference between current_timestamp and now() in quotes

On 22/01/2009 13:52, Grzegorz Jaśkiewicz wrote:

test2=# insert into dupa(a) select 'current_timestamp' from
generate_series(1,100);
ERROR: date/time value "current" is no longer supported

This doesn't answer your question, but you use current_timestamp without
the quotes, thus -

insert into dupa(a) select current_timestamp ...

Ray.

------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod@iol.ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------

#3Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Grzegorz Jaśkiewicz (#1)
Re: difference between current_timestamp and now() in quotes

Grzegorz Jaśkiewicz escribió:

test2=# insert into dupa(a) select 'current_timestamp' from
generate_series(1,100);
ERROR: date/time value "current" is no longer supported
LINE 1: insert into dupa(a) select 'current_timestamp' from generate...
^
test2=# insert into dupa(a) select 'now()' from generate_series(1,100);
INSERT 0 100

Any ideas why the difference ?

The parser handles CURRENT_TIMESTAMP (and others) specially, and doesn't
recognize it in quotes. I don't know why 'now()' works; I think it is a
literal of type unknown. I guess it's expanded to the actual value in
later parsing stages.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

#4Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Alvaro Herrera (#3)
Re: difference between current_timestamp and now() in quotes

On Thursday 22 January 2009 8:16:46 am Alvaro Herrera wrote:

Grzegorz Jaśkiewicz escribió:

test2=# insert into dupa(a) select 'current_timestamp' from
generate_series(1,100);
ERROR: date/time value "current" is no longer supported
LINE 1: insert into dupa(a) select 'current_timestamp' from generate...
^
test2=# insert into dupa(a) select 'now()' from generate_series(1,100);
INSERT 0 100

Any ideas why the difference ?

The parser handles CURRENT_TIMESTAMP (and others) specially, and doesn't
recognize it in quotes. I don't know why 'now()' works; I think it is a
literal of type unknown. I guess it's expanded to the actual value in
later parsing stages.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

At least on 8.2 'now()' does not work either at least not in the way I think
you want. I get:

test=# SELECT 'now()';
?column?
----------
now()
(1 row)

--
Adrian Klaver
aklaver@comcast.net

#5Jason Long
mailing.list@supernovasoftware.com
In reply to: Adrian Klaver (#4)
Re: difference between current_timestamp and now() in quotes

Adrian Klaver wrote:

On Thursday 22 January 2009 8:16:46 am Alvaro Herrera wrote:

Grzegorz Jaśkiewicz escribió:

test2=# insert into dupa(a) select 'current_timestamp' from
generate_series(1,100);
ERROR: date/time value "current" is no longer supported
LINE 1: insert into dupa(a) select 'current_timestamp' from generate...
^
test2=# insert into dupa(a) select 'now()' from generate_series(1,100);
INSERT 0 100

Any ideas why the difference ?

The parser handles CURRENT_TIMESTAMP (and others) specially, and doesn't
recognize it in quotes. I don't know why 'now()' works; I think it is a
literal of type unknown. I guess it's expanded to the actual value in
later parsing stages.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

At least on 8.2 'now()' does not work either at least not in the way I think
you want. I get:

test=# SELECT 'now()';
?column?
----------
now()
(1 row)

Try
select now();

#6Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Jason Long (#5)
Re: difference between current_timestamp and now() in quotes

On Thursday 22 January 2009 9:07:37 am Jason Long wrote:

Adrian Klaver wrote:

On Thursday 22 January 2009 8:16:46 am Alvaro Herrera wrote:

Grzegorz Jaśkiewicz escribió:

test2=# insert into dupa(a) select 'current_timestamp' from
generate_series(1,100);
ERROR: date/time value "current" is no longer supported
LINE 1: insert into dupa(a) select 'current_timestamp' from generate...
^
test2=# insert into dupa(a) select 'now()' from generate_series(1,100);
INSERT 0 100

Any ideas why the difference ?

The parser handles CURRENT_TIMESTAMP (and others) specially, and doesn't
recognize it in quotes. I don't know why 'now()' works; I think it is a
literal of type unknown. I guess it's expanded to the actual value in
later parsing stages.

--
Alvaro Herrera
http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom
Development, 24x7 support

At least on 8.2 'now()' does not work either at least not in the way I
think you want. I get:

test=# SELECT 'now()';
?column?
----------
now()
(1 row)

Try
select now();

Yes that is how I use it :) My example referred to the original message that
said select 'now()' worked but 'current_timestamp' did not.

--
Adrian Klaver
aklaver@comcast.net

#7Grzegorz Jaśkiewicz
gryzman@gmail.com
In reply to: Adrian Klaver (#4)
Re: difference between current_timestamp and now() in quotes

well, I am asking that - for pure curiosity reason.
I got a function in C, that automagically puts all data in quotes, and
that's how I came across that strange difference between current_time
and now(). Funny enough, pg will translate first one to latter in
domains, for instance.

#8Osvaldo Kussama
osvaldo.kussama@gmail.com
In reply to: Adrian Klaver (#4)
Resp.: difference between current_timestamp and now() in quotes

2009/1/22, Adrian Klaver <aklaver@comcast.net>:

On Thursday 22 January 2009 8:16:46 am Alvaro Herrera wrote:

Grzegorz Jaśkiewicz escribió:

test2=# insert into dupa(a) select 'current_timestamp' from
generate_series(1,100);
ERROR: date/time value "current" is no longer supported
LINE 1: insert into dupa(a) select 'current_timestamp' from generate...
^
test2=# insert into dupa(a) select 'now()' from generate_series(1,100);
INSERT 0 100

Any ideas why the difference ?

The parser handles CURRENT_TIMESTAMP (and others) specially, and doesn't
recognize it in quotes. I don't know why 'now()' works; I think it is a
literal of type unknown. I guess it's expanded to the actual value in
later parsing stages.

--
Alvaro Herrera
http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

At least on 8.2 'now()' does not work either at least not in the way I
think
you want. I get:

test=# SELECT 'now()';
?column?
----------
now()
(1 row)

Table 8-13. Special Date/Time Inputs
http://www.postgresql.org/docs/current/interactive/datatype-datetime.html

bdteste=# SELECT 'now'::date, 'yesterday'::date, 'today'::date,
'tomorrow'::date;
date | date | date | date
------------+------------+------------+------------
2009-01-22 | 2009-01-21 | 2009-01-22 | 2009-01-23
(1 registro)

Osvaldo

#9Reg Me Please
regmeplease@gmail.com
In reply to: Osvaldo Kussama (#8)
Re: Resp.: difference between current_timestamp and now() in quotes

On Thursday 22 January 2009 18:57:16 Osvaldo Kussama wrote:

2009/1/22, Adrian Klaver <aklaver@comcast.net>:

On Thursday 22 January 2009 8:16:46 am Alvaro Herrera wrote:

Grzegorz Jaśkiewicz escribió:

test2=# insert into dupa(a) select 'current_timestamp' from
generate_series(1,100);
ERROR: date/time value "current" is no longer supported
LINE 1: insert into dupa(a) select 'current_timestamp' from
generate... ^
test2=# insert into dupa(a) select 'now()' from
generate_series(1,100); INSERT 0 100

Any ideas why the difference ?

The parser handles CURRENT_TIMESTAMP (and others) specially, and doesn't
recognize it in quotes. I don't know why 'now()' works; I think it is a
literal of type unknown. I guess it's expanded to the actual value in
later parsing stages.

--
Alvaro Herrera
http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

At least on 8.2 'now()' does not work either at least not in the way I
think
you want. I get:

test=# SELECT 'now()';
?column?
----------
now()
(1 row)

Table 8-13. Special Date/Time Inputs
http://www.postgresql.org/docs/current/interactive/datatype-datetime.html

bdteste=# SELECT 'now'::date, 'yesterday'::date, 'today'::date,
'tomorrow'::date;
date | date | date | date
------------+------------+------------+------------
2009-01-22 | 2009-01-21 | 2009-01-22 | 2009-01-23
(1 registro)

Osvaldo

'now' != 'now()'

And also the cast matters, IMHO.

--
Fahrbahn ist ein graues Band
weisse Streifen, grüner Rand

#10Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Adrian Klaver (#4)
Re: difference between current_timestamp and now() in quotes

Adrian Klaver escribi�:

At least on 8.2 'now()' does not work either at least not in the way I think
you want. I get:

test=# SELECT 'now()';
?column?
----------
now()
(1 row)

alvherre=# select 'now()'::unknown::timestamptz;
timestamptz
-------------------------------
2009-01-22 15:01:46.352979-03
(1 fila)

It even works if you use "text" instead of unknown.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

#11Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Alvaro Herrera (#10)
Re: difference between current_timestamp and now() in quotes

On Thursday 22 January 2009 10:04:05 am Alvaro Herrera wrote:

Adrian Klaver escribió:

At least on 8.2 'now()' does not work either at least not in the way I
think you want. I get:

test=# SELECT 'now()';
?column?
----------
now()
(1 row)

alvherre=# select 'now()'::unknown::timestamptz;
timestamptz
-------------------------------
2009-01-22 15:01:46.352979-03
(1 fila)

It even works if you use "text" instead of unknown.

I see my problem I was just doing a select. When I did an insert into a
timestamp field than the 'now()' form worked. Learn something new everyday :)

--
Adrian Klaver
aklaver@comcast.net

#12Jasen Betts
jasen@xnet.co.nz
In reply to: Grzegorz Jaśkiewicz (#1)
Re: difference between current_timestamp and now() in quotes

On 2009-01-22, Adrian Klaver <aklaver@comcast.net> wrote:

On Thursday 22 January 2009 8:16:46 am Alvaro Herrera wrote:

Grzegorz Jaśkiewicz escribió:

test2=# insert into dupa(a) select 'current_timestamp' from
generate_series(1,100);
ERROR: date/time value "current" is no longer supported
LINE 1: insert into dupa(a) select 'current_timestamp' from generate...
^
test2=# insert into dupa(a) select 'now()' from generate_series(1,100);
INSERT 0 100

Any ideas why the difference ?

The parser handles CURRENT_TIMESTAMP (and others) specially, and doesn't
recognize it in quotes. I don't know why 'now()' works; I think it is a
literal of type unknown. I guess it's expanded to the actual value in
later parsing stages.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

At least on 8.2 'now()' does not work either at least not in the way I think
you want. I get:

test=# SELECT 'now()';
?column?
----------
now()
(1 row)

'now' is a string which can be translated to timestamp
now() is a function that returns the current timestamp
current_timestamp is a constant that does the same

#13Dhaval Jaiswal
bablu_postgres@yahoo.com
In reply to: Grzegorz Jaśkiewicz (#1)
Re: difference between current_timestamp and now() in quotes

"current_timestamp" is the reserved keyword of postgreSQL. When you executes it within single quotation mark it treated as string & that is the only reason it thrown error.

"Now()" is an in-built function you can use it with/without single quotation mark.

For more information refere the below link.
http://www.postgresql.org/docs/8.1/static/sql-keywords-appendix.html

--
Thanks & Regards
Dhaval Jaiswal
EnterpriseDB
www.enterprisedb.com

 

________________________________
From: Grzegorz Jaśkiewicz <gryzman@gmail.com>
To: GENERAL <pgsql-general@postgresql.org>
Sent: Thursday, January 22, 2009 7:22:21 PM
Subject: [GENERAL] difference between current_timestamp and now() in quotes

test2=# create table dupa(a timestamp,  b serial);
NOTICE:  CREATE TABLE will create implicit sequence "dupa_b_seq" for
serial column "dupa.b"
CREATE TABLE

test2=# insert into dupa(a) select current_timestamp from
generate_series(1,100);
INSERT 0 100

test2=# insert into dupa(a) select 'current_timestamp' from
generate_series(1,100);
ERROR:  date/time value "current" is no longer supported
LINE 1: insert into dupa(a) select 'current_timestamp' from generate....
                                  ^
test2=# insert into dupa(a) select 'now()' from generate_series(1,100);
INSERT 0 100

Any ideas why the difference ?

--
GJ

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general