From 11e4ae196d6e3c8a86f967ba8384f600263a0d8f Mon Sep 17 00:00:00 2001 From: RandomEtc Date: Fri, 29 Jun 2012 19:55:07 -0700 Subject: [PATCH] Added a note about WHERE foo IN (...) queries with links to #82 and #129 --- FAQ.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/FAQ.md b/FAQ.md index 43bdc7b..044d569 100644 --- a/FAQ.md +++ b/FAQ.md @@ -122,4 +122,18 @@ If a prepared statement has a `name`, it is only parsed once. After that, `name ### 10. Can we override the built in data converters between javascript and postgres data types? -Yes, [here is a test that shows how it can be done.](https://github.com/brianc/node-postgres/blob/master/test/integration/client/huge-numeric-tests.js#L6) And for some examples of already registered converters, [look at this file.](https://github.com/brianc/node-postgres/blob/master/lib/textParsers.js) \ No newline at end of file +Yes, [here is a test that shows how it can be done.](https://github.com/brianc/node-postgres/blob/master/test/integration/client/huge-numeric-tests.js#L6) And for some examples of already registered converters, [look at this file.](https://github.com/brianc/node-postgres/blob/master/lib/textParsers.js) + + +### 11. How do I build a `WHERE foo IN (...)` query to find rows matching an array of values? + +You need to flatten your array of values and build the numbered placeholder string for yourself. + +```javascript +// passing an array as a value __won't work__: +client.query("SELECT * FROM stooges WHERE name IN ($1)", [ ['larry', 'curly', 'moe'] ], ...); +// passing a flat array of values will work: +client.query("SELECT * FROM stooges WHERE name IN ($1, $2, $3)", ['larry', 'curly', 'moe'], ...); +``` + +See [#129](https://github.com/brianc/node-postgres/issues/129) and [#82](https://github.com/brianc/node-postgres/issues/82) for more details. \ No newline at end of file