title: How to detect if current_setting is null
body: <p>I’m writing a function which gets if the current user has “starred” a row. The current user’s id is stored in a local variable and accessible through the postgresql <code>current_setting</code> function. How do I provide a default value for <code>current_setting</code>? Here is my function:</p>
  
  <pre><code>CREATE FUNCTION current_user_starred(star_group_id integer)
    RETURNS boolean
    AS $$
      SELECT COUNT(*) != 0
        FROM star
       WHERE star_group_id = star_group_id
         AND starrer_id = current_setting('user_id')::integer;
    $$
    LANGUAGE sql;
  </code></pre>
  
  <p>For a default setting I would like to use -1 or 0 for <code>current_setting('user_id')</code>.</p>