I'm trying to use COALESCE to deal with sql injections in Go.
query := `SELECT mc.company_name_full, msc.company_id, msc.cdate, %s
FROM %s AS mc INNER JOIN %s AS msc
ON (mc.id = msc.company_id)
WHERE %s AND
msc.company_id = COALESCE($1, msc.company_id) AND
mc.company_name_full ~* COALESCE($2, mc.company_name_full) AND
msc.cdate >= '2017-07-01' AND
msc.cdate <= '%s'`
query = fmt.Sprintf(query, selectParam, companyTable, statsTable, whereParam, time.Now().Local().Format("2006-01-02"))
This query works, but when I try to use COALESCE with Time_stamp
query := `SELECT mc.company_name_full, msc.company_id, msc.cdate, %s
FROM %s AS mc INNER JOIN %s AS msc
ON (mc.id = msc.company_id)
WHERE %s AND
msc.company_id = COALESCE($1, msc.company_id) AND
mc.company_name_full ~* COALESCE($2, mc.company_name_full) AND
msc.cdate >= COALESCE($3, '2017-07-01') AND
msc.cdate <= COALESCE($4, '%s')`
but I get this error
pq:operator does not exist: timestamp without time zone >= text
What can I do to ensure that COALESCE returns a timestamp type?