SQL 如何在hsqldb中“选择current_timestamp”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/909702/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 02:12:54  来源:igfitidea点击:

How to do "select current_timestamp" in hsqldb?

sqldatabasehsqldbembedded-database

提问by cherouvim

Oracle:

甲骨文:

select systimestamp from dual

MySQL:

MySQL:

select current_timestamp

SQL Server:

SQL 服务器:

select current_timestamp

PostgreSQL:

PostgreSQL:

select current_timestamp

The question is, how can I get the current timestamp in HSQLDB? I use version 1.8.0.10

问题是,如何在HSQLDB 中获取当前时间戳?我使用版本 1.8.0.10

采纳答案by alexdown

You can write

你可以写

select current_timestamp from tablename  

where tablenameis a real table in your database.

tablename数据库中的真实表在哪里。

The result of the query is only the current timestamp.

查询的结果只是当前时间戳。

回答by jeanlou1370

In a select I use

在我使用的选择中

 SELECT CURRENT_DATE AS today, CURRENT_TIME AS now FROM (VALUES(0))

回答by pilcrow

@alexdown's answeris quite right -- under 1.8 you need a one-row relation to do this, like Oracle's DUALor the InterBase/Firebird RDB$DATABASEtable.

@alexdown 的回答非常正确——在 1.8 下,您需要一个单行关系来执行此操作,例如 OracleDUAL或 InterBase/FirebirdRDB$DATABASE表。

When you move to the 2.0 series, however, you'll be able to use the SQL-99 "VALUES constructor" without reliance on a one-row relation:

但是,当您转到 2.0 系列时,您将能够使用 SQL-99“VALUES 构造函数”而无需依赖单行关系:

sql> VALUES (current_timestamp);
2010-04-22 15:22:40.997

If you need to rename the column from the vendor-specific defaults that VALUES picks, you can always employ a select: SELECT * FROM (VALUES (current_timestamp)) v(my_new_name)

如果您需要从 VALUES 选择的特定于供应商的默认值中重命名列,您始终可以使用选择: SELECT * FROM (VALUES (current_timestamp)) v(my_new_name)

回答by fredt

With HSQLDB 2.1 and later you have all the options.

使用 HSQLDB 2.1 及更高版本,您拥有所有选项。

With the connection property hsqldb.syntax_ora, hsqldb.syntax_pgs, hsqldb.syntax_mss or hsqldb.syntax_mys=true you can use the forms supported by other databases. The equivalent SQL is SET DATABASE SQL SYNTAX ORA TRUE, and similar for other dialects.

通过连接属性 hsqldb.syntax_ora、hsqldb.syntax_pgs、hsqldb.syntax_mss 或 hsqldb.syntax_mys=true,您可以使用其他数据库支持的形式。等效的 SQL 是SET DATABASE SQL SYNTAX ORA TRUE,其他方言也类似。

The native, SQLStandard form, supported by HSQLDB in all modes is this:

HSQLDB 在所有模式下都支持的原生 SQLStandard 形式是这样的:

VALUES (CURRENT_TIMESTAMP)

回答by Thilo-Alexander Ginkel

You can use

您可以使用

CALL current_timestamp

to retrieve the current timestamp. According to a discussion on the HSQL mailing list this is much more efficient than doing a dummy select from INFORMATION_SCHEMA.SYSTEM_TABLES.

检索当前时间戳。根据 HSQL 邮件列表上的讨论,这比从INFORMATION_SCHEMA.SYSTEM_TABLES.