postgreSQL 中 from dual 的等价
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30303638/
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
equivalence of from dual in postgreSQL
提问by franco
I work with hibernate and oracle
我使用 hibernate 和 oracle
I used this code :
我使用了这个代码:
if (null != sessionFactory) {
Session s = currentSession.get();
if ((null == s) || !s.isOpen()) {
s = sessionFactory.openSession();
currentSession.set(s);
} else {
try {
HibernateWork hibernateWork = new HibernateWork("SELECT 1 FROM DUAL");
s.doWork(hibernateWork);
} catch (Exception e) {
s = sessionFactory.openSession();
currentSession.set(s);
}
}
return s;
}
I want to do the same thing with postgreSQL
我想用 postgreSQL 做同样的事情
but PostgreSQL does NOT support the ‘FROM dual' syntax
但 PostgreSQL 不支持“FROM dual”语法
I want to know equivalence of dualin postgreSQL
我想知道postgreSQL 中对偶的等价性
回答by Nick Barnes
You don't need a FROM
clause at all. Just SELECT 1
will do it.
你根本不需要FROM
条款。只需SELECT 1
将做到这一点。
回答by Predrag Maric
Just use select 1
. From documentation
只需使用select 1
. 从文档
Oracle uses the "fake" dual table for many selects, where in PostgreSQL we can write selectjust without frompart at all. This table was created in postgres as a view to ease porting problems. This allows code to remain somewhat compatible with Oracle SQL without annoying the Postgres parser.
Oracle 对许多选择使用“假”双表,而在 PostgreSQL 中,我们可以完全不用from部分来编写select。这个表是在 postgres 中创建的,目的是为了缓解移植问题。这允许代码在某种程度上与 Oracle SQL 兼容,而不会打扰 Postgres 解析器。
回答by Amit Vujic
PostgreSQL has implicit DUAL table, just write:
PostgreSQL 有隐含的 DUAL 表,只需写:
SELECT NOW ()
Output:
2019-05-17 13:56:51.120277+02
In case that you Oracle PL/SQL code is referring DUAL table you can create own DUAL table:
如果您的 Oracle PL/SQL 代码引用 DUAL 表,您可以创建自己的 DUAL 表:
CREATE TABLE moldb.public.dual (
column1 bool);
回答by Frank Heikens
Just create one, if you really want to:
只要创建一个,如果你真的想:
CREATE TABLE dual();