sqlpostgresqlstring-constant

Error: column does not exist when in fact it does? why?


I have the following PostgreSQL query below. If I remove one line AND r.type = "long_form" it works fine. I'm not sure why PostgreSQL is not liking that line:

SELECT  TRUNC(DATE_PART('day', CURRENT_DATE - r.created_at )/7)  AS weeks_ago,
        date(min(r.created_at)) AS "Date Start",
        date(max(r.created_at)) AS "Date End",
        count(*) as  "Reviews in Cohort",
        AVG(has_note::int) as "Reviews w 1 or more Notes Ratio"
FROM (SELECT r.id, r.created_at,
             ( MAX(rn.note) IS NOT NULL ) as has_note
      FROM reviews f JOIN
           reviewss_notes rn
           ON r.id = rn.review_id

            WHERE r.completed_at IS NOT NULL
                    AND r.created_at > '2019-01-01'
                    AND r.type = "long_form"

            GROUP BY r.id
     ) f
GROUP BY weeks_ago
ORDER BY weeks_ago DESC;

Here is the line in the query causing the issues:

AND r.type = "long_form"

The table's design includes a column of:

enter image description here

What am I doing wrong here?


Solution

  • check your quote characters ...

    AND r.type = 'long_form'
    

    Use single quotes are for string constants.