pg-copy-stream crashes when using the copy postgres command in lambda

35 Views Asked by At

I am trying to write a lambda which will be used to get data from PostgreSQL using a query. I am using pg-copy-stream's 'to' function to convert my query into a stream and passing it to client.query().

When I run tests locally they crash saying that "could not send data to client broken pipe" (found this in my PostgreSQL table log).

My connection to PostgreSQL client also terminates when this line is executed.

I have already done an exhaustive research but am unable to figure out why this is happening.

I have considered other options as well but pg-copy-stream library should work as expected if I am following the documentation right.

Here is the code where the connection terminates:

const createReadableStream = (pgClient: Client): CopyToStreamQuery => { 
const exportQuery = "copy (select * from schema.view as scv where scv.number = 200) to stdout with (format csv, delimiter ',', quote '\"', header);";
return pgClient.query(copyTo(exportQuery));
};
0

There are 0 best solutions below