How to use Confluence metadata in SQL queries

Description

In many cases, you may want your query to know the current logged in user, what page the query is on, or other Confluence related metadata. This is easily done using the Run Self-Service Reports for Confluence and various pre-defined variables. 

For SQL for Confluence release 5.2 and later, a special substitution variable @user_id@ is available as well. The SQL macros replaces this text with the user ID of the currently logged in user or anonymous, if the user is not logged in.