patternsqlMinor
dual table postgres doesn't return timestamp
Viewed 0 times
postgresreturndoesntimestampdualtable
Problem
I am trying to select now() from my local postgres database dual table:
It returns no rows. Just prints column name
What is it that I am missing that it cannot get the system time?
select now() from dual;It returns no rows. Just prints column name
now(yyyy-MM-dd HH:mm:ss.ffffff)What is it that I am missing that it cannot get the system time?
Solution
Don't create
Why are you using a dual table in PostgreSQL to begin with? PostgreSQL has an implicit dual table if there is no from-clause.
You can also
Creating a
You'll never need a dual table with PostgreSQL, and you shouldn't create one: it just convolutes the syntax. It's also foreign for most PostgreSQL users. That said, it's easy to demonstrate that it works..
dual tablesWhy are you using a dual table in PostgreSQL to begin with? PostgreSQL has an implicit dual table if there is no from-clause.
SELECT now(); -- works fine.You can also
SELECT * FROM now(); -- works fine.- For more information, see my answer to Why does
SELECT count(*)return 1?
Creating a
dual table should still workYou'll never need a dual table with PostgreSQL, and you shouldn't create one: it just convolutes the syntax. It's also foreign for most PostgreSQL users. That said, it's easy to demonstrate that it works..
test=# CREATE TABLE dual AS ( VALUES (true) );
SELECT 1
test=# SELECT now() FROM dual ;
now
-------------------------------
2017-10-05 15:34:34.359092-05
(1 row)Code Snippets
SELECT now(); -- works fine.SELECT * FROM now(); -- works fine.test=# CREATE TABLE dual AS ( VALUES (true) );
SELECT 1
test=# SELECT now() FROM dual ;
now
-------------------------------
2017-10-05 15:34:34.359092-05
(1 row)Context
StackExchange Database Administrators Q#187800, answer score: 7
Revisions (0)
No revisions yet.