[SOLVED] Error with Badge SQL


(Andrew LeCody) #1

I have a cronjob that automatically populates a table “whmcs_emails” with the e-mail address of active users from another system. The idea is that any discourse account with an e-mail that matches this list will be granted a badge.

Here is the SQL statement I’m using:

SELECT u.id user_id, current_timestamp granted_at
FROM users u, whmcs_emails w
WHERE u.email = w.addr AND
(:backfill OR u.id IN (:user_ids) )

This is the error I’m getting:

PG::Error: ERROR:  permission denied for relation whmcs_emails
: SELECT COUNT(*) count FROM (SELECT u.id user_id, current_timestamp granted_at
FROM users u, whmcs_emails w
WHERE u.email = w.addr AND
('t' OR u.id IN (NULL) )) q WHERE 't' = 't'

I don’t have much experience with PostgreSQL, is there an easy fix for this issue?


(Andrew LeCody) #2

I figured out my issue. The whmcs_emails table was owned by the postgres user and not the discourse user.


(Robin Ward) #3