Postgres Case Expression Errors
I'm attempting to create a PostgreSQL case expression that is based on job posting status. For example:
- When
statusis'Closed', I want the difference in days between theupdated_attimestamp and thecreated_attimestamp. - When
statusis either'Open'or'Pending', I want to subtract thecreated_attimestamp from the current timestamp.
The query I've created so far is listed below:
Select users.first_name || " " || users.last_name,
users.email,
organizations.name,
organizations.vertical,
jobs.name,
jobs.id
(Case
When jobs.status = 'Closed' Then jobs.updated_at - jobs.created_at Else 'Not Closed') END AS days_to_hire,
(Case
When jobs.status IN ('Open,'Pending') Then current_timestamp - jobs.created_at Else 'Closed_or_Deleted') END AS days_open,
FROM organizations
JOIN users on organizations.id = users.organization_id
JOIN jobs on user.id= jobs.user.id
It does not work as I expect, though:
ERROR: syntax error at or near ")"
And I have not been able to figure out why.