Executing SQL doesn't work in psql

I’m trying to execute:

SELECT user_id, 0 post_id, current_timestamp granted_at 
FROM badge_posts  
WHERE (:backfill OR user_id IN (:user_ids) OR 0 NOT IN (:post_ids) )
GROUP BY user_id 
HAVING count(*) > 1000

but I’m getting an error on :backfill. Can anyone tell me why?

I know this SQL used to run in badge creation.

Anything starting with a : is a named parameter meant to be replaced by mini_sql prior to being sent to the DBMS, it’s not valid SQL by itself.

Example, see [2] below:

[1] pry(main)> User.find_by(username: 'anon43915857').id
=> 5

[2] pry(main)> DB.query(
  "SELECT id FROM users WHERE username = :username",
  { username: 'anon43915857' }
).first.id
=> 5

[3] pry(main)> DB.query(
  "SELECT id FROM users WHERE username = ?",
  'anon43915857' 
).first.id
=> 5
3 Likes

Thank you. This is clear.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.