1

I am facing a very annoying PSQL issue when trying to load part of a PostgreSQL table via a subquery.

The query is :

SELECT 
    N1,
    N2, 
    N3,
    N4
FROM CORR 
WHERE CORR_N5 >= (now() - interval '18 year') 
AND CORR_N5 <= (now() - interval '18 year' + interval '1 month')

This one works if written directly in PgAdmin. However when I run it from a spark 2 job, I get tho following error message :

org.postgresql.util.PSQLException: ERROR: subquery in FROM must have an alias
  Hint: For example, FROM (SELECT ...) [AS] foo.

Even when I put an alias after all the clauses, the same issue happens.

Any advice ?

Thanks in advance

Melvin C.
  • 13
  • 2

1 Answers1

0

Melvin, have a look at the below links

https://pganalyze.com/docs/log-insights/app-errors/U115

subquery in FROM must have an alias

SELECT * FROM (
    SELECT N1, N2, N3, N4 
    FROM CORR WHERE COR_N5 >= (now() - interval '18 year') 
    AND CORR_N5 <= (now() - interval '18 year' + interval '1 month')
) AS input
Melvin C.
  • 13
  • 2
  • Thank you very much Mansoor, my issue was solved by your input and a simple upgrade of my postgre driver's version. Have a great weekend. Melvin – Melvin C. Sep 28 '18 at 10:35