Difference between NOW and CURRENT_TIMESTAMP

1,674 views
Skip to first unread message

Volk

unread,
Mar 21, 2007, 7:25:19 AM3/21/07
to H2 Database
CURRENT_TIMESTAMP and NOW functions are synonyms, but this code is
executed :
CREATE TABLE TEST (
Created DATETIME DEFAULT CURRENT_TIMESTAMP NOT
NULL
);

while this one don't :

CREATE TABLE TEST (
Created DATETIME DEFAULT NOW NOT NULL
);

"Column NOW not found; SQL statement: CREATE TABLE TEST1 (
Created DATETIME DEFAULT NOW NOT NULL
) [42S22-44]
org.h2.jdbc.JdbcSQLException: Column NOW not found; SQL statement:
CREATE TABLE TEST1 (
Created DATETIME DEFAULT NOW NOT NULL
) [42S22-44]
at org.h2.message.Message.addSQL(Message.java:348)
at org.h2.command.Parser.parse(Parser.java:226)
at org.h2.command.Parser.prepareCommand(Parser.java:191)
at org.h2.engine.Session.prepareLocal(Session.java:174)
at org.h2.engine.Session.prepareCommand(Session.java:156)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:
993)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:143)
at org.h2.server.web.AppThread.getResult(AppThread.java:945)
at org.h2.server.web.AppThread.query(AppThread.java:615)
at org.h2.server.web.AppThread.process(AppThread.java:71)
at org.h2.server.web.WebServerThread.run(WebServerThread.java:127)
org.h2.jdbc.JdbcSQLException: Column NOW not found [42S22-44]
at org.h2.message.Message.getSQLException(Message.java:65)
...
"

P.S.
And this one is working :
CREATE TABLE TEST (
Created DATETIME DEFAULT NOW() NOT NULL
);

Thomas Mueller

unread,
Mar 23, 2007, 11:03:48 PM3/23/07
to h2-da...@googlegroups.com
Hi,
This is by design. NOW is a function (MS SQL Server compatibility) and
needs the (), while CURRENT_TIMESTAMP is a pseudo column (as defined
by the ANSI standard) and does not need ().

Thomas

Reply all
Reply to author
Forward
0 new messages