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

The child doesn't actually access the database. It runs a few backtick commands and processes the results. All of the database access is done from the parent. I have another function that works in a similar way but the parent pushes data to the child, and it works OK.

Replies are listed 'Best First'.
Re^3: Wierd pipe behaviour in plperlu
by pc88mxer (Vicar) on Jun 04, 2008 at 23:30 UTC
    Can you post some code that exhibits the problem? Thanks.
      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.
      The original code is too big to post, but I'll see if I can cobble together a test case.