Question

How to run postgresql script (psql -f file_with_sql.sql) in SQL executor

  • 24 September 2019
  • 2 replies
  • 8 views

Badge

I want to run bunch of postgreSQL SQL's through a file using psql command.

To check whether psql works in SQLExecutor, I tried putting below statement SQL executor.

psql -c 'SELECT * FROM testdb.test';

 

However, I got below error.

psql -c 'SELECT * FROM testdb.test';'): 'ERROR: syntax error at or near "psql"

LINE 3: psql -c 'SELECT * FROM testdb.test;

^

'

A fatal error has occurred. Check the logfile above for details

 

Can you please help.


2 replies

Userlevel 4

If it's really a psql script you should use the SystemCaller and call the psql command line tool there.

If the script contains regular SQL you can copy/paste the query itself into the SQLExecutor:

select * from testdb.test

Note that it does not include the semi-colon at the end.

 

Userlevel 2
Badge +12

If it reads from a table another option would be using the FeatureReader transformer.

You can point that transformer to the table or use the SQL statement to get the records.

Reply