Repository navigation
Allow running postgres_query on a specific conn - #614
Merged
Merged
Conversation
This PR adds 2 new scalar functions:
- `postgres_pin_connection`(`<attached_database_name>`: `VARCHAR`) -> `UBIGINT`
- `postgres_close_pinned_connection`(`<attached_database_name>`: `VARCHAR`, `<connection_id>`: `UBIGINT`) -> BOOL
`postgres_pin_connection` acquires a connection from the connection pool
of the specified attached database and "pins" that connection returning
its ID as a handle. This handle can be specified to the
`postgres_query()` function to make it run on that specific connection.
This allows to make multiple subsequent `postgres_query()` and
`postgres_execute()` calls on the same connection, thus keeping
consistent server session state.
Pinned connection remains "active" and takes a slot in the connection
pool until it is closed by calling `postgres_close_pinned_connection`.
Usage example:
```sql
ATTACH '...' AS s (TYPE postgres);
SET VARIABLE conn = postgres_pin_connection('s');
CALL postgres_execute('s', 'CREATE TEMPORARY TABLE temp1(col1 INT)', connection=getvariable('conn'));
CALL postgres_execute('s', 'INSERT INTO temp1 values(42)', connection=getvariable('conn'));
FROM postgres_query('s', 'SELECT * FROM temp1', connection=getvariable('conn'));
----
00:42:00
SELECT postgres_close_pinned_connection('s', getvariable('conn'));
```
Testing: `query_pin_connection.test` added.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds 2 new scalar functions:
postgres_pin_connection(<attached_database_name>:VARCHAR) ->UBIGINTpostgres_close_pinned_connection(<attached_database_name>:VARCHAR,<connection_id>:UBIGINT) ->BOOLpostgres_pin_connectionacquires a connection from the connection pool of the specified attached database and "pins" that connection returning its ID as a handle. This handle can be specified to thepostgres_query()function to make it run on that specific connection. This allows to make multiple subsequentpostgres_query()andpostgres_execute()calls on the same connection, thus keeping consistent server session state.Pinned connection remains "active" and takes a slot in the connection pool until it is closed by calling
postgres_close_pinned_connection.Usage example:
Testing:
query_pin_connection.testadded.