in reply to Re^2: Wierd pipe behaviour in plperlu
in thread Wierd pipe behaviour in plperlu

Can you post some code that exhibits the problem? Thanks.

Replies are listed 'Best First'.
Re^4: Wierd pipe behaviour in plperlu
by Anonymous Monk on Jun 05, 2008 at 08:24 UTC
    The original code is too big to post, but I'll see if I can cobble together a test case.
Re^4: Wierd pipe behaviour in plperlu
by Anonymous Monk on Jun 05, 2008 at 10:32 UTC
    I found the problem while creating a test case for you to look at! It's amazing how stripping everything back to the bare bones can help! Turns out to be nothing to do with pipes, file handles or forking. The problem was down to the scope of the buffer variable. I had declared it as 'our' and the value seemed to persist between invocations of the function. Wasn't expecting that - I thought %_SHARED was used for that purpose! I have now changed it to 'local' and the problem goes away. Have a look at the following test case:
    CREATE OR REPLACE FUNCTION myFunction() RETURNS TEXT LANGUAGE PLPERLU AS $BODY$ our $data; $data .= 'xx'; return $data; $BODY$
    scratch=# select myFunction();
     myfunction 
    ------------
     xx
    (1 row)
    
    scratch=# select myFunction();
     myfunction 
    ------------
     xxxx
    (1 row)
    
    scratch=# select myFunction();
     myfunction 
    ------------
     xxxxxx
    (1 row)
    
    Changing to 'local $data' solves the problem. Thanks for your suggestions and interest.