Обсуждение: print statements?

Поиск
Список
Период
Сортировка

print statements?

От
tlm
Дата:
[ 2nd try ]

Hi.  I have an automated script that essentially feeds a long sequence of  SQL statements to psql, as a single transaction.  For debugging purposes, I would like to insert the equivalent of print statements (to write messages to stdout, stderr, or maybe some pre-specified log file) at various points in this sequence.  How is this done?

Thanks!

tlm

Re: print statements?

От
"Brandon Aiken"
Дата:

The easiest method would be to write the script using PHP, Perl, or similar.  That would allow everything to be in one transaction while still allowing you to do output and things like exception handling.

 

--

Brandon Aiken

CS/IT Systems Engineer


From: pgsql-novice-owner@postgresql.org [mailto:pgsql-novice-owner@postgresql.org] On Behalf Of tlm
Sent: Tuesday, December 19, 2006 8:35 AM
To: pgsql-novice@postgresql.org
Subject: [NOVICE] print statements?

 

[ 2nd try ]

Hi.  I have an automated script that essentially feeds a long sequence of  SQL statements to psql, as a single transaction.  For debugging purposes, I would like to insert the equivalent of print statements (to write messages to stdout, stderr, or maybe some pre-specified log file) at various points in this sequence.  How is this done?

Thanks!

tlm

Re: print statements?

От
Andreas Kretschmer
Дата:
tlm <tlm1905@gmail.com> schrieb:

> [ 2nd try ]
>
> Hi.  I have an automated script that essentially feeds a long sequence of  SQL
> statements to psql, as a single transaction.  For debugging purposes, I would
> like to insert the equivalent of print statements (to write messages to stdout,
> stderr, or maybe some pre-specified log file) at various points in this
> sequence.  How is this done?

One solution: write a little function to write out there parameter via
RAISE NOTICE and call this function on the desired places.

I mean something tike this:

test=# create function write_out(text) returns void as $$ begin raise notice '%',$1; end; $$ language plpgsql immutable
strict;
CREATE FUNCTION
test=#
test=# select write_out('hint');
NOTICE:  hint
 write_out
-----------

(1 row)


and set 'log_min_messages = notice', then can you find your messages in
the log-file.


Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."    (unknow)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

Re: print statements?

От
Frank Bax
Дата:
At 08:35 AM 12/19/06, tlm wrote:
>Hi.  I have an automated script that essentially feeds a long sequence
>of  SQL statements to psql, as a single transaction.  For debugging
>purposes, I would like to insert the equivalent of print statements (to
>write messages to stdout, stderr, or maybe some pre-specified log file) at
>various points in this sequence.  How is this done?


  select 'half way already?';


Re: print statements?

От
Tom Lane
Дата:
Frank Bax <fbax@sympatico.ca> writes:
> At 08:35 AM 12/19/06, tlm wrote:
>> Hi.  I have an automated script that essentially feeds a long sequence
>> of  SQL statements to psql, as a single transaction.  For debugging
>> purposes, I would like to insert the equivalent of print statements (to
>> write messages to stdout, stderr, or maybe some pre-specified log file) at
>> various points in this sequence.  How is this done?

>   select 'half way already?';

Also, there's a \echo command in psql that might help.

            regards, tom lane