Skip site navigation (1) Skip section navigation (2)

Re: Sending messages inside a function

From: Chris Campbell <chris(at)bignerdranch(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Sending messages inside a function
Date: 2005-11-29 19:10:08
Message-ID: 6181AE7C-E0E5-44A1-9E02-5E6A246A06B9@bignerdranch.com (view raw or flat)
Thread:
Lists: pgsql-interfaces
On Nov 29, 2005, at 13:28, Tom Lane wrote:

> You cannot control the FE/BE protocol from inside a user function.

"cannot" is a bit strong -- the function in my original email did it,  
and it works (with caveats). It's good to know that I "should" not,  
though. I'm still curious why I got the error message:

     server sent data ("D" message) without prior row description  
("T" message)

Is the 'T' message sent back to the client before my function was  
invoked? Can the 'T' message be suppressed until immediately before  
the first piece of tuple data is returned to the client? That way, I  
could do my COPY operation before the 'T' message is sent and no one  
would be the wiser.

>> This seems more efficient to me than passing BYTEAs back and forth.
>
> Why?  A byte is a byte.  There is no possible way that you will ever
> save enough microseconds from this to repay the development time you
> will waste trying to kluge the system to do it.

Does that still apply to BYTEAs that are tens (hundreds?) of  
megabytes? I was hoping to stream the data so that I wouldn't have to  
read it all into memory and pass it to the function (or return it  
from the function) as one big chunk. That way, the first part could  
be going out over the network while the function was reading in the  
rest of the data. It wouldn't have to wait to read the entire piece  
of data into memory before transmitting it. I could also put up a  
nice little progress bar for the transfer.

If I pass in the data as a BYTEA parameter to the function, is the  
data transmitted completely before the function is invoked? If the  
function fails before it even needs the data (due to an invalid  
argument, etc), it seems wasteful to have transmitted it across the  
wire.

I also wanted to avoid the hassle of having to massage the binary  
data (escaping values, etc) before transmitting it, but perhaps using  
the binary format in libpq is all that's needed. Can I easily turn a  
buffer of data into a BYTEA and pass it to PQexecParams()?

Thanks!

- Chris


In response to

pgsql-interfaces by date

Next:From: Michael FuhrDate: 2005-11-30 03:53:51
Subject: Re: pl/pyton: exceptions.ImportError: No module named email.Parser
Previous:From: Tom LaneDate: 2005-11-29 18:28:18
Subject: Re: Sending messages inside a function

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group