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.
hibernate - Equivalence of from dual in PostgreSQL - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.
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.
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.
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.
You don't need a FROM
clause at all. Just SELECT 1
will do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With