app.get('/api/search', async (req, res) => {
const { instanceId, packageType, os, instanceType, startDate, endDate } = req.query;
console.log("here at receiving query: ", instanceId, packageType, os, instanceType, startDate, endDate);
console.log(typeof(instanceId));
try {
const query = `
SELECT * FROM packages_db
WHERE
($1 IS NULL OR instance_id = $1) AND
($2 IS NULL OR package_modules = $2) AND
($3 IS NULL OR os_type_version = $3) AND
($4 IS NULL OR instance_type = $4) AND
($5 IS NULL OR creation_time BETWEEN $5 AND $6);`
// Execute the SQL query with the provided parameters
const result = await pool.query(query, [instanceId, packageType, os, instanceType, startDate, endDate]);
// Return the result from the database
res.json(result.rows);
} catch (error) {...}
Error : Error executing query: error: could not determine data type of parameter $1
Tried to specify the datatype that didn’t work.
const query = `
SELECT * FROM packages_db
WHERE
($1 IS NULL OR instance_Id = ($1::text)::integer) AND
($2 IS NULL OR package_modules = $2::text) AND
($3 IS NULL OR os_type_version = $3::text) AND
($4 IS NULL OR instance_type = $4::text) AND
($5 IS NULL OR creation_time BETWEEN $5::timestamp AND $6::timestamp);`
// Execute the SQL query with the provided parameters
const result = await pool.query(query, [instanceId, packageType, os, instanceType, startDate, endDate]);
Got this error instead:
Error executing query: error: syntax error at end of input
New contributor
Harsh Garg is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1