-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
queries such as “SELECT * FROM city WHERE countrycode=$1 ORDER BY district” are ok.
However, when using “ORDER BY $1”, then ORDER is ignored.
How to replicate:
psql -f world.sql (https://gist.github.com/scottsd/5118089)
pg.connect(process.env.DATABASE_URL, function(err, db) {
var sql = "SELECT * FROM city "
sql += " WHERE countrycode='PHL' "
sql += " ORDER BY $1 LIMIT 20 OFFSET 20"
console.log(sql)
db.query(sql, ["district, name"], function(err, result) {
responseBody.data = result.rows
res.send(JSON.stringify(responseBody))
})
})
results:
{
"data": [
{
"id": 789,
"name": "Iligan",
"countrycode": "PHL",
"district": "Central Mindanao",
"population": 285061
},
{
"id": 790,
"name": "Calamba",
"countrycode": "PHL",
"district": "Southern Tagalog",
"population": 281146
},
{
"id": 791,
"name": "Mandaluyong",
"countrycode": "PHL",
"district": "National Capital Reg",
"population": 278474
},
…