Search code examples
hibernatepostgresql

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.


Solution

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