使用 date_part 时出现此错误
error: function date_part(timestamp without time zone, unknown) does not exist
有时我会得到一个时间戳值,有时却为空。那么如何处理空值呢?
SELECT u.id as user_id
, u.firstname
, u.lastname
, c.id as company_id
, c.company
, wt.start_time as available_at
, wt.end_time as available_until
FROM users u
LEFT JOIN workers_times wt
ON wt.user_id = u.id
LEFT JOIN clients c
ON c.id = u.company_id
WHERE u.tenant_id = $2
AND u.deleted_by IS NULL
AND DATE_PART(wt.work_date, 'month') = 4
AND DATE_PART(wt.work_date, 'day') = 11
GROUP BY u.id
ORDER BY u.id DESC
, u.created_by DESC
LIMIT 100
只需尝试正确的语法,首先是部分,其次是内容:
来自手册: