When I create the following function in PostgreSQL:
create function log( value variadic text[] )
returns void
language plpython3u
as $$
print( ' '.join( value ) + '\n' )
$$;
do $$ begin perform log( ( 42 + 108 )::text ); end; $$;
the ouput does not appear in the terminal (using psql -f ...
). Where does it go instead?
Also, isn't there any simple way (maybe an extension) that gives me an easy-to-use output to stdout
/ stderr
? I do not want to use select
since that surrounds all output with table decorations, which you can turn off, but only using psql
tricks that do not work in functions. Likewise, I do not want to use \echo
, as that won't work within function definitions.
Edit I know about plpy.notice()
, but that function surrounds its output with a whole lot of clutter, too.
BTW my solution right now is to write to a file:
create function log( value variadic text[] )
returns void
language plpython3u
as $$
with open( '/tmp/psql-output', 'a' ) as o:
o.write( ' '.join( value ) + '\n' )
$$;
and have a tail running in the background (that uses ANSI colors, yay!):
tail -f /tmp/psql-output | sed 's/^.*$/\x1b[38;05;214m\0\x1b[0m/g' &
but the disadvantage is that I need external code to set up this thing.