Perl + Postgresql: function does not return value if NOTIFICATION NOTIFICATIONS

I noticed that when I call the PL / PgSQL or PL / Perl function from a Perl script using DBI, it does not return a value if the function uses RAISE NOTICE or elog (NOTICE). To illustrate:

Simple table:

CREATE TABLE "public"."table1" (
  "fld" INTEGER
) WITHOUT OIDS;

Simple function:

CREATE OR REPLACE FUNCTION "public"."function1" () RETURNS integer AS
$body$
DECLARE
  myvar INTEGER;
BEGIN
  SELECT INTO myvar fld FROM table1 LIMIT 1;
  RETURN myvar;
END;
$body$
LANGUAGE 'plpgsql'

Perl script part:

use DBI;
...
my $ref = $dbh->selectcol_arrayref('SELECT function1()');
print $$ref[0];

As it is, it prints the value from the table.

But I don't get any result if I add RAISE NOTICE as follows:

SELECT INTO myvar fld FROM table1 LIMIT 1;
RAISE NOTICE 'Testing';
RETURN myvar;

Am I missing something or is this design behavior?

+3
source share
2 answers

Check the option client_min_messagesin your database server file postgresql.conf. From PostgreSQL 8.3 docs:

client_min_messages (line)

, . : DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, LOG, NOTICE, WARNING, ERROR, FATAL PANIC. , . , . NOTICE. , LOG , log_min_messages.

+2

, Debian Perl 5.10, DBI 1.605 DBD:: Pg 2.8.7 PostgreSQL 8.3.7. , .

steve@steve@[local] =# create or replace function public.function1() returns integer language 'plpgsql' as $$ declare myvar integer; begin select into myvar fld from table1 limit 1; raise notice 'Testing'; return myvar; end; $$;
CREATE FUNCTION
steve@steve@[local] =#
[1]+  Stopped                 psql --cluster 8.3/steve
steve@arise:~$ DBI_TRACE=1 perl -MData::Dumper -MDBI -e '$dbh = DBI->connect(qw|dbi:Pg:dbname=steve;port=5433;host=/tmp steve steve|, {RaiseError=>1,PrintError=>0}); print Data::Dumper->new([$dbh->selectcol_arrayref("SELECT function1()")], [qw|result|])->Dump'
    DBI 1.605-ithread default trace level set to 0x0/1 (pid 5739) at DBI.pm line 273 via -e line 0
    Note: perl is running without the recommended perl -w option
    -> DBI->connect(dbi:Pg:dbname=steve;port=5433;host=/tmp, steve, ****, HASH(0x1c9ddf0))
    -> DBI->install_driver(Pg) for linux perl=5.010000 pid=5739 ruid=1000 euid=1000
       install_driver: DBD::Pg version 2.8.7 loaded from /usr/lib/perl5/DBD/Pg.pm
    <- install_driver= DBI::dr=HASH(0x1e06a68)
    !! warn: 0 CLEARED by call to connect method
    <- connect('dbname=steve;port=5433;host=/tmp', 'steve', ...)= DBI::db=HASH(0x1fd8e08) at DBI.pm line 638
    <- STORE('RaiseError', 1)= 1 at DBI.pm line 690
    <- STORE('PrintError', 0)= 1 at DBI.pm line 690
    <- STORE('AutoCommit', 1)= 1 at DBI.pm line 690
    <- STORE('Username', 'steve')= 1 at DBI.pm line 693
    <> FETCH('Username')= 'steve' ('Username' from cache) at DBI.pm line 693
    <- connected('dbi:Pg:dbname=steve;port=5433;host=/tmp', 'steve', ...)= undef at DBI.pm line 699
    <- connect= DBI::db=HASH(0x1fd8e08)
    <- STORE('dbi_connect_closure', CODE(0x1da2280))= 1 at DBI.pm line 708
NOTICE:  Testing
    <- selectcol_arrayref('SELECT function1()')= ( [ '2' ] ) [1 items] at -e line 1
$result = [
            '2'
          ];

script ( ) DBI_TRACE, , , . , DBD:: Pg , , , , . DBI_TRACE=10 :

PQexec
Begin pg_warn (message: NOTICE:  Testing
 DBIc_WARN: 1 PrintWarn: 1)
NOTICE:  Testing
End pg_warn
Begin _sqlstate

, - .

+1

Source: https://habr.com/ru/post/1708279/


All Articles