How to pass an array as param?
See original GitHub issueNewbie to PG.
Passing the following Query works fine:
'INSERT sessions(all_programs) values(ARRAY[UUID(\'c6dc4514-8e7b-4043-9eb8-c7fd8ad2c306\')]) RETURNING *;'
Is there a way to pass the array of UUID as a param? The following very naive attempt:
const result = (await db.query(
'INSERT sessions(all_programs) values($1) RETURNING *;'),
['ARRAY[UUID(\'c6dc4514-8e7b-4043-9eb8-c7fd8ad2c306\')]']);
Results in an err.
For completeness, the table schema is:
CREATE TABLE sessions ( session_uuid UUID PRIMARY KEY DEFAULT uuid_generate_v4(), all_programs UUID ARRAY );
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Passing Arrays as Function Arguments in C - Tutorialspoint
If you want to pass a single-dimension array as an argument in a function, you would have to declare a formal parameter in...
Read more >Pass arrays to a function in C - Programiz
To pass an entire array to a function, only the name of the array is passed as an argument. result = calculateSum(num);. However,...
Read more >How to pass an array within a query string? - Stack Overflow
Here's what I figured out: Submitting multi-value form fields, i.e. submitting arrays through GET/POST vars, can be done several different ...
Read more >Passing arrays as arguments - C# Programming Guide
Arrays can be passed as arguments to method parameters. Because arrays are reference types, the method can change the value of the elements....
Read more >How Arrays are Passed to Functions in C/C++? - GeeksforGeeks
A whole array cannot be passed as an argument to a function in C++. You can, however, pass a pointer to an array...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@AxelTerizaki The SQL syntax for
foo IN (...)
is for an inline values list. You can’t put a parameter in place of the list. Instead, use the array comparison constructANY
:I’d like to reopen this as this is exactly the issue I’m having with a simple :
DELETE FROM table WHERE id IN $1
I pass params like that :
query(myQuery, [ids])
where
ids
is an array of strings.What I get in the postgres log (with all statements enabled) is kinda funny :
Sorry the log is in french but it’s basically “syntax error on or near $1 at character 35”
It’s almost as if the query wasn’t being parameterized
It works if instead of passing $1 I manually do something dirty like this :
I’m using node-postgres 8.6.0.
The snippet I posted above is working for me as a workaround, but it’s kind of messy and I wonder why this isn’t working even though it should.