Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalence of from dual in PostgreSQL

I work with Hibernate and 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, but PostgreSQL does NOT support the ‘FROM dual’ syntax. I want to know equivalence of dual in PostgreSQL.

like image 489
franco Avatar asked May 18 '15 12:05

franco


People also ask

What is equivalent of dual in Postgres?

hibernate - Equivalence of from dual in PostgreSQL - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.

Is there any dual table in PostgreSQL?

There is no “dual” table Unlike other RDBMS, PostgreSQL allows a “select” without the ”from” clause. This use does not affect portability because the syntax to get current time is already DBMS specific.

What does SELECT 1 from dual mean?

In your case, SELECT 1 FROM DUAL; will simply returns 1 . You need it because the INSERT ALL syntax demands a SELECT clause but you are not querying the input values from a table.

What is Nextval in Postgres?

NEXTVAL is a function to get the next value from a sequence. Sequence is an object which returns ever-increasing numbers, different for each call, regardless of transactions etc. Each time you call NEXTVAL , you get a different number. This is mainly used to generate surrogate primary keys for you tables.


1 Answers

You don't need a FROM clause at all. Just SELECT 1 will do it.

like image 170
Nick Barnes Avatar answered Sep 17 '22 15:09

Nick Barnes