You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow partial pipelining within a transaction #951
Allow pipelining the some requests in a transaction without requiring that all the requests are pipelined. This would allow selecting to get the id of a row, then issuing multiple statements based on the id of the row in a pipelined fashion.
For example:
awaitsql.begin(asyncsql=>{const[movie]=awaitsql` SELECT * FROM Movie WHERE name = 'Star Wars' `;return[sql` INSERT INTO MovieActor -- some statement using ${movie.id} `,sql` INSERT INTO MovieReleases -- some statement using ${movie.id} `,// etc]})
Alternatively, maybe there could be a specific sql.pipeline() function, which would accept an array of sql statements to pipeline. This would allow opening a transaction and running some non-pipelined statements before and after a block of pipelined statements.
I think your example is great, and ought to work :) Also for doing it in the middle of other queries this should be supported:
awaitsql.begin(asyncsql=>{const[movie]=awaitsql` SELECT * FROM Movie WHERE name = 'Star Wars' `awaitPromise.all([sql` INSERT INTO MovieActor -- some statement using ${movie.id} `,sql` INSERT INTO MovieReleases -- some statement using ${movie.id} `,// etc])awaitsql` ... something else `})
I might have some time to toy with this soon, but if you want to take a stab at it, feel free :)
I think Promise.all doesn't guarantee any sequencing, while pipelining with libpq does. This doesn't matter in many cases, but it can occasionally. For example, you could do an INSERT, then another INSERT that uses some aggregate that includes the first INSERT, etc.
CTEs can work in most situations, but it would be nice to have the option to pipeline statements.
Another place where partial pipelining would be great is when using temporary tables. For example:
awaitsql.pipeline(sql=>[sql` CREATE TEMP TABLE ActorsInYear ON COMMIT DROP AS SELECT Actor.* FROM Actor JOIN MovieActor USING (ActorId) JOIN Movie USING (MovieId) WHERE Movie.Year = ${year} `,sql` CREATE INDEX ON ActorsInYear(ActorId) `,sql` ANALYZE ActorsInYear `]);// Do something with ActorsInYear
Activity
astralarya commentedon Oct 3, 2024
Alternatively, maybe there could be a specific
sql.pipeline()function, which would accept an array of sql statements to pipeline. This would allow opening a transaction and running some non-pipelined statements before and after a block of pipelined statements.porsager commentedon Oct 3, 2024
I think your example is great, and ought to work :) Also for doing it in the middle of other queries this should be supported:
I might have some time to toy with this soon, but if you want to take a stab at it, feel free :)
porsager commentedon Oct 3, 2024
Until then, are you sure your use case can't work with CTE's ?
astralarya commentedon Oct 3, 2024
I think
Promise.alldoesn't guarantee any sequencing, while pipelining with libpq does. This doesn't matter in many cases, but it can occasionally. For example, you could do an INSERT, then another INSERT that uses some aggregate that includes the first INSERT, etc.CTEs can work in most situations, but it would be nice to have the option to pipeline statements.
astralarya commentedon Dec 11, 2024
Another place where partial pipelining would be great is when using temporary tables. For example:
oscar6echo commentedon Mar 28, 2025
There should be a way to keep the sequence order: #1030 (comment)
karlhorky commentedon Aug 20, 2026
@mcollina wrote about recently implementing pipelining in
pgand its impact:@porsager would you also accept such a contribution here?
porsager commentedon Aug 20, 2026
It's been there since day one 😉 I think this issue is about handling it explicitly
karlhorky commentedon Aug 20, 2026
Ah nice! I was wondering if that pipelining feature was this bit from the readme:
porsager commentedon Oct 29, 2026
v4 documents and tests this: queries in a
Promise.allbetween awaited ones are sent together and run in the order they were made.