Tengo esta función en el servidor postgres
CREATE OR REPLACE FUNCTION get_lastdata_id_test(_sensor text)
RETURNS TABLE (id uuid, sid text,ts timestamp without time zone, measure double precision) AS
$func$
SELECT id,sensor_id, date, measure
FROM measures
WHERE sensor_id = $1
ORDER BY date
DESC LIMIT 13
$func$ LANGUAGE sql;
y una API para obtener los datos desde el servidor postgres
app.get('/last/:id', (request, response) => {
const sid = parseInt(request.params.id)
pool.query("SELECT * FROM get_lastdata_id_test($1)",[sid], (error, results) => {
if (error) {
throw error
}
response.status(200).json(results.rows)
})
})
Si pruebo la función en el servidor postgres select * from get_lastdata_id_test('sen-01')
Obtengo lo siguiente:
"f2c9fc2d-7ef8-49ee-9b72-a018e12c33a1" "sen-01" "2019-08-29 23:59:07" "1021.57"
"d381cd44-b017-4531-aa23-b4b7bb81138e" "sen-01" "2019-08-29 23:55:59" "1005.95"
"345c8073-edc1-4e4a-9950-1a0bfb661b38" "sen-01" "2019-08-29 14:47:31" "1005.95"
"841e6a43-0756-4ef5-ae77-e8ff3f9a3638" "sen-01" "2019-08-29 13:20:16" "994.23"
"caba2781-ec9a-49e5-a190-72a7fd47b292" "sen-01" "2019-08-29 13:16:24" "988.37"
"99b40219-fb2a-4534-9b49-0a4ecce92cba" "sen-01" "2019-08-29 13:08:28" "984.46"
"d16e805b-3a83-4b87-a414-fe05b03ecfbe" "sen-01" "2019-08-29 12:57:30" "978.6"
"80f0d046-8c43-46bf-9200-dc58465f5163" "sen-01" "2019-08-29 12:48:42" "988.37"
"b6eed4dc-301e-44d4-962b-d7d4b1b6dc8b" "sen-01" "2019-08-29 12:44:48" "998.13"
"15e82547-6b89-41eb-b427-f0659dd0c9e0" "sen-01" "2019-08-29 12:36:47" "990.32"
"735ae26a-78a0-4fe0-af67-9baaa8902f14" "sen-01" "2019-08-29 12:32:49" "992.28"
"cf82c4ad-128d-44a5-8c28-9ac4f552eca5" "sen-01" "2019-08-29 12:21:16" "986.42"
"eafe87ac-9e17-448c-a7e6-ff96e4191243" "sen-01" "2019-08-29 12:09:08" "968.84"
Pero usando la url de la API http://localhost:3000/last/sen-01 No obtengo datos:
[ ]
Cómo puedo pasar correctamente el argumento a la función a través de la URL de la API 'quote'?