question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pass several queries to Postgres at the same time and have the results returned together

See original GitHub issue

It would be useful if we could chain one query made up of multiple other queries and send them all to the server at once (for performance reasons) rather than as multiple separate queries. And the results would be returned together.

select firstfunction($1, $2); select secondfunction($3, $4, $5, $6); select thirdfunction($7);

In this example there would only be one roundtrip from the application to the database rather than 3. And there would be something like an array of 3 results because there are 3 queries.

I can make a Postgres function for things like this but that’s less useful in cases like this where you can have several different combinations of queries you’re sending to the server from various parts of your application, and you wouldn’t want to be making several Postgres functions for each combination of queries you’ll send to the database.

I see https://github.com/brianc/node-postgres/wiki/Parameterized-queries-and-Prepared-Statements#multi-statement-parameterized-queries but I mean batching the queries on the client (node-postgres) rather than in Postgres itself.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
brianccommented, May 12, 2017

I’m going to close this but keep that old stale PR open so I’ll have a reminder to fix it. Thanks for drawing it to my attention! ❤️

1reaction
rightawaycommented, Jan 8, 2017

I don’t know if a real performance improvement can be expected from this.

Wouldn’t it increase performance by saving round trips to the database? Why do you think it might not have a real improvement?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to combine multiple queries into a single result set ... - EDB
This article discusses methods for comparing and combining multiple queries into a single result set in PostgreSQL.
Read more >
Execute multiple queries in a single statement using postgres ...
For now node-postgres handles multiple queries in one call and returns a neat little array to you, like: const db.query('select 1; select 2; ......
Read more >
7.8. WITH Queries (Common Table Expressions) - PostgreSQL
The WITH clause defines two auxiliary statements named regional_sales and top_regions ... Include all remaining rows in the result of the recursive query, ......
Read more >
15: 38.5. Query Language (SQL) Functions - PostgreSQL
SQL functions execute an arbitrary list of SQL statements, returning the result of the last query in the list. In the simple (non-set)...
Read more >
15: 7.4. Combining Queries (UNION, INTERSECT, EXCEPT)
The results of two queries can be combined using the set operations union, ... they return the same number of columns and the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found