Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Supports array arguments in prepared statements #1892

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

Open
ritalin wants to merge 1 commit into duckdb:main
base: main
Choose a base branch
Loading
from ritalin:add_array_placeholder

Conversation

Copy link

@ritalin ritalin commented Oct 11, 2024
edited
Loading

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(?))

Fil, martenbjork, azu, and controversial reacted with thumbs up emoji e1arikawa, domoritz, martenbjork, azu, and controversial reacted with heart emoji

This comment was marked as resolved.

Copy link
Author

ritalin commented Nov 3, 2024
edited
Loading

@Fil
This is type

The following is correct:

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

Thanks!

Fil and e1arikawa reacted with thumbs up emoji

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

Reviewers

@carlopi carlopi Awaiting requested review from carlopi

@domoritz domoritz Awaiting requested review from domoritz

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /