Thread: psql -af > out, is possible to also have raise notice, raise info part.

hi.

test.sql content:
--------------------------------------------------------------------------------------------------
do $$
begin
  raise info 'information message %', now() ;
  raise debug 'debug message %', now();
  raise notice 'notice message %', now();
end $$;
--------------------------------------------------------------------------------------------------
psql -af test.sql > test.out

current result:
--------------------------------------------------------------------------------------------------
do $$
begin
  raise info 'information message %', now() ;
  raise notice 'notice message %', now();
end $$;
DO
--------------------------------------------------------------------------------------------------
expected result in test.out

do $$
begin
  raise info 'information message %', now() ;
  raise notice 'notice message %', now();
end $$;
INFO:  information message 2023-07-12 11:49:27.894126+08
NOTICE:  notice message 2023-07-12 11:49:27.894126+08
DO



Re: psql -af > out, is possible to also have raise notice, raise info part.

From
"David G. Johnston"
Date:
On Tue, Jul 11, 2023 at 8:52 PM jian he <jian.universality@gmail.com> wrote:
hi.

test.sql content:
--------------------------------------------------------------------------------------------------
do $$
begin
  raise info 'information message %', now() ;
  raise debug 'debug message %', now();
  raise notice 'notice message %', now();
end $$;
--------------------------------------------------------------------------------------------------
psql -af test.sql > test.out


You've only redirected stdout (file # 1 - implied), the "raise" stuff goes to stderr (file # 2)

IIRC you can do:

psql -af test.sql > test.out 2>&1

(order matters, left-to-right)

But you can search online for "output redirection in Linux" or some such if you want to learn the Linux command line better.

David J.

On Wed, Jul 12, 2023 at 12:06 PM David G. Johnston
<david.g.johnston@gmail.com> wrote:
>
> On Tue, Jul 11, 2023 at 8:52 PM jian he <jian.universality@gmail.com> wrote:
>>
>> hi.
>>
>> test.sql content:
>> --------------------------------------------------------------------------------------------------
>> do $$
>> begin
>>   raise info 'information message %', now() ;
>>   raise debug 'debug message %', now();
>>   raise notice 'notice message %', now();
>> end $$;
>> --------------------------------------------------------------------------------------------------
>> psql -af test.sql > test.out
>>
>
> You've only redirected stdout (file # 1 - implied), the "raise" stuff goes to stderr (file # 2)
>
> IIRC you can do:
>
> psql -af test.sql > test.out 2>&1
>
> (order matters, left-to-right)
>
> But you can search online for "output redirection in Linux" or some such if you want to learn the Linux command line
better.
>
> David J.
>

thanks.
I don't know that "raise" stuff goes to stderr.
To get rid of the line numbers, I use "psql -a < test.sql > test.out
2>&1 " to get the expected result.