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

Supports array arguments in prepared statements #1892

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ritalin
Copy link

@ritalin ritalin commented Oct 11, 2024

Description

This PR implements in supporting an array arguments in the prepared statements (issue #447).

Usage

You can pass Javascript's array as argument for query / send method of AsyncPreparedStatement.

const stmt = await conn.prepare(`SELECT * FROM range(1, ?::int) t(id) WHERE id = ANY(?)`);
const result = await stmt.query(100, [2, 3, 5, 7, 11]); 

query / send method of PreparedStatement can also apply similarly.

Out-of -scope

It does not expand IN clause value.
For instance, WHERE foo IN (?::int[]) is not converted to such as WHERE foo IN (?, ?, ?).
If you want to use an array parameter at IN clause, you can use following:

SELECT * FROM range(1, ?::int) t(id) WHERE id IN(SELECT unnest(?))

@carlopi carlopi requested review from carlopi and domoritz October 29, 2024 10:12
@Fil

This comment was marked as resolved.

@ritalin
Copy link
Author

ritalin commented Nov 3, 2024

@Fil
This is type

The following is correct:

SELECT * FROM range(1, ?::int) t(id) WHERE id IN(SELECT unnest(?));

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants