postgresql earthdistance拡張機能を使用してクエリを作成しようとしていますが、計算列を返したいのですが、次のエラーが発生し続けます:テーブル "670906、-79"のFROM句エントリがありません。 これはおそらく、パーサーがテーブル名と列名をドットで区切ると考えているためですが、私の場合は計算を実行しています(以下のクエリ例を参照)。 これを回避する方法はありますか?
Possibly unhandled error: missing FROM-clause entry for table "670906,-79"
at Connection.parseE (/usr/local/lib/node_modules/pg/lib/connection.js:534:11)
at Connection.parseMessage (/usr/local/lib/node_modules/pg/lib/connection.js:361:17)
at Socket.<anonymous> (/usr/local/lib/node_modules/pg/lib/connection.js:105:22)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:764:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:426:10)
at emitReadable (_stream_readable.js:422:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
var columns = [
'id',
'(earth_distance(ll_to_earth(lat, lng), ll_to_earth(43.670906, -79.393331)) as distance)'
];
var result = knex
.select(columns)
.from('stores')
.whereRaw('earth_box(ll_to_earth(43.670906, -79.393331), ?) @> ll_to_earth(lat, lng)', [radiusInStatuteMiles])
計算列にはknex.raw
を使用する必要があるため、引用符で囲まれません。 以下が機能するはずです。
var columns = [
'id',
knex.raw('earth_distance(ll_to_earth(lat, lng), ll_to_earth(43.670906, -79.393331)) as distance')
];
var result = knex
.select(columns)
.from('stores')
.whereRaw('earth_box(ll_to_earth(43.670906, -79.393331), ?) @> ll_to_earth(lat, lng)', [radiusInStatuteMiles])
ありがとう! まさに私が必要としていたもの。 どういうわけかknex.raw
を使用することを考えていません
どういたしまして!
最も参考になるコメント
計算列には
knex.raw
を使用する必要があるため、引用符で囲まれません。 以下が機能するはずです。