How can I replace a BIT value in the dataset returned by a SELECT statement with a STRING (of words, no numbers) in PostgreSQL? I'm very new to SQL in general, so my experience and googleing has not proved bountiful.
In this particular case, c.visible is a bit value storing either 0 (is visible) or 1 (not visible). In my query, I want to show all results where c.visible = 0, but display 'this course is visible to students.' instead of '0' in the dataset returned by this select statement. I've tried casting it as text in the SELECT statement, then changing the value in a CASE WHEN statement in the WHERE clause, but this results in an invalid input syntax error. c.visibility is the only attribute in the database that records this information.
For example:
--------------------------------------------------------
| CourseName | ID | CourseVisibility |
--------------------------------------------------------
| ABC | 10 | This course is visible to students.|
--------------------------------------------------------
| DEF | 22 | This course is visible to students.|
--------------------------------------------------------
SELECT c.fullname AS CourseName, c.id AS ID, CAST(c.visible AS TEXT) AS CourseVisibilty
FROM prefix_course c, prefix_logstore_standard_log lsl
WHERE
c.visible = 0
CASE WHEN c.visible = '0'
THEN c.visible = 'This course is visible to students.'
END
AND lsl.courseid = c.id
AND lsl.timecreated BETWEEN extract(epoch from NOW()- INTERVAL '12 month') AND extract(epoch from NOW())
GROUP BY c.fullname, c.id, c.visible
ERROR: invalid input syntax for integer: "This course is visible to students."
LINE 5: THEN c.visible = 'This course is visible to students.'
^
What is the correct method to do this?
booleancolumn is a much better choice than abitcolumn