1

I would like to do the following:

psql -c "COPY (SELECT a.id, b.id FROM a JOIN b USING id) TO STDOUT;"

the problem is that it would never send anything until the join is fully computed. Is there a way to tell Postgres to output the join while its being computed without writing it into a some temporary storage?

1 Answer 1

1

Use psql's \copy.

\COPY (SELECT a.id, b.id FROM a JOIN b USING id) TO stdout;

You can replace stdout with '/path/to/file' if desired.

An inner join can be incrementally computed, so there should be no issues there presuming the tables aren't views over more complex queries. Show the output of explain select ... if you still don't get incremental output.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks, that seems to do the job. my join is slightly more complex than a JOIN B
Actually, from the docs of psql: \copy { table [ ( column_list ) ] | ( query ) } { from | to } { 'filename' | program 'command' | stdin | stdout | pstdin | pstdout } [ [ with ] ( option [, ...] ) ] Performs a frontend (client) copy. This is an operation that runs an SQL COPY(7) command, but instead of the server reading or writing the specified file, psql reads or writes the file and routes the data between the server and the local file system. So its same as COPY TO .. STDOUT with respect to JOIN computation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.