0

I am writing a BASH Shell Script to execute one SELECT query on postgreSQL and also print a custom message before the SELECT Query o/p.

FYI...

PGPASSWORD=XXXXX psql --host=XXX --port=5432 --username=XXXXX --dbname=XXXXX << EOF

        DO language plpgsql $$
        BEGIN
        raise notice 'USER';
        END
        $$;
        SELECT email,username,count(*) FROM users GROUP BY username,email HAVING count(*) > 1;


EOF

But this is throwing ERROR, as it replaces $$ with the PID. How can i resolve this. What can i use instead of $$.

Philip Couling
  • 13,581
  • 5
  • 53
  • 85
Rohith
  • 1,077
  • 5
  • 16
  • 36
  • Have you tried escaping the `$$`? E.g., `\$\$`? –  Dec 20 '17 at 04:11
  • Alternatively, use single quotes instead of double dollar signs. (See e.g. https://stackoverflow.com/questions/12144284/what-are-used-for-in-pl-pgsql .) –  Dec 20 '17 at 04:13
  • Thanks..! it works. But is there any other way we can print messages apart form raise notice..!? – Rohith Dec 20 '17 at 04:24
  • `echo "message"`? –  Dec 20 '17 at 06:32

0 Answers0