Home PostgreSQL: Declare a cursor for prepared statement
Reply: 0

PostgreSQL: Declare a cursor for prepared statement

Marcin Barczyński
1#
Marcin Barczyński Published in 2018-01-12 16:07:21Z

The following DECLARE fails:

PREPARE stmt(bigint) AS SELECT ...;
DECLARE crs CURSOR FOR stmt;

According to https://www.postgresql.org/docs/9.6/static/sql-declare.html, stmt has to be either SELECT or VALUES command.

I use PREPARE statement in a latency-critical section of the code in which thousands of quick queries are emitted. Parsing and generating a query plan each time would be performance killer. However, in some rare cases the query can return millions of records and the result doesn't fit into memory.

Is there a way to declare a cursor for prepared statement in PostgreSQL? If not, are there any workarounds?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.342022 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO