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.
You can use the function of plpy to print the message.
plpy.debug(msg, **kwargs)
plpy.log(msg, **kwargs)
plpy.info(msg, **kwargs)
plpy.notice(msg, **kwargs)
plpy.warning(msg, **kwargs)
plpy.log() is always output if log_destination is "stderr", and others functions are according to log_min_messages value(warning is default).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With