Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map slice elements into clauses #3578

Open
richardhuaaa opened this issue Sep 4, 2024 · 1 comment
Open

Map slice elements into clauses #3578

richardhuaaa opened this issue Sep 4, 2024 · 1 comment

Comments

@richardhuaaa
Copy link

What do you want to change?

Is there any support for passing a slice of variable length and mapping it into clauses of a postgres query, like in this pseudo-code?

SELECT
  ...
WHERE
   ...
   AND (originator_node_id NOT IN $1::int[]
     OR (originator_node_id = $1[0] AND originator_sequence_id > $2[0])
     OR (originator_node_id = $1[1] AND originator_sequence_id > $2[1])
     ...
     );

What database engines need to be changed?

PostgreSQL

What programming language backends need to be changed?

Go

@richardhuaaa richardhuaaa added the enhancement New feature or request label Sep 4, 2024
@richardhuaaa
Copy link
Author

richardhuaaa commented Sep 4, 2024

For anyone else in the same situation, I've found a workaround, although I'm unsure yet how the performance compares:

WITH cursors AS (
	SELECT
		UNNEST(@cursor_node_ids::INT[]) AS cursor_node_id,
		UNNEST(@cursor_sequence_ids::BIGINT[]) AS cursor_sequence_id
)
SELECT
	envelopes.*
FROM
	envelopes
	LEFT JOIN cursors ON envelopes.originator_node_id = cursors.cursor_node_id
WHERE ...
AND (cursor_sequence_id IS NULL
	OR envelopes.originator_sequence_id > cursor_sequence_id)
...;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant