0

I am trying to select an item from a table where a given number fit's into its cost range.

It seems to work if I manually set $/cost/ to a 3.136 but as soon as I try to use a named parameter it fails. I am using other variables int he full query and they all work fine, which leads me to believe I am doing something incorrectly as it pertains to pg-promise and numrange

db.one('SELECT id FROM cost_table WHERE range @> $/cost/', { cost })

I get the error

Server running on port 5000
[0] { error: malformed range literal: "3.316"
[0]     at Connection.parseE (\node_modules\pg\lib\connection.js:602:11)
...
So on so forth
...
name: 'error',
[0]   length: 137,
[0]   severity: 'ERROR',
[0]   code: '22P02',
[0]   detail: 'Missing left parenthesis or bracket.',
[0]   hint: undefined,
[0]   position: '1896',
[0]   internalPosition: undefined,
[0]   internalQuery: undefined,
[0]   where: undefined,
[0]   schema: undefined,
[0]   table: undefined,
[0]   column: undefined,
[0]   dataType: undefined,
[0]   constraint: undefined,
[0]   file: 'rangetypes.c',
[0]   line: '2092',
Matt Weber
  • 2,808
  • 2
  • 14
  • 30

0 Answers0