1

I'm trying to find a one-liner to read query from external file and output psql NOTICEs to a log file. I tried :

psql -h host -d database -U username -f my_sql_file.sql > my_log_file.log

my_sql_file.sql has a multiline anonymous block like :

DO
$$
DECLARE
  stuff 
BEGIN
   RAISE NOTICE '--------- TEST ----------';
END;
$$

The log file outputs the first line of the file : "DO" and nothing else.

1 Answer 1

2

The notice gets written to standard error, so redirect that too:

psql -h host -d database -U username -f my_sql_file.sql > my_log_file.log 2>&1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.