SQL Snippets

👤 This documentation is intended for SQL Users.

SQL Snippets can be used to create a simple string of SQL that can be reused in as many charts as desired.

<LI><a href="#CreateSnippet">Creating a Snippet</a></LI>
<LI><a href="#UseSnippet">Using Snippets In Charts</a></LI>
<LI><a href="#SnippetSettings">Snippet Settings</a></LI>
<LI><a href="#Tags">Tagging a Snippet</a></LI>
<LI><a href="#Description">Adding a Description</a></LI>
<LI><a href="#Owner">Changing a Snippet Owner</a></LI>


<a name="CreateSnippet"></a>

Creating A Snippet

To create a SQL snippet, click on the "SQL Snippets" menu item in the sidebar:

Click the "+" button and name the snippet.

Note: Snippet names cannot contain the characters < > : " / \ | ? *
Snippets with these characters included will be unable to sync with any GIT repository connected to the site.

Simply type the SQL in the box and click save. The below example shows a snippet called User_is_real that will filter out spambots, admins, and deleted users in any of the charts it is added to.

<a href="#top">Back to top</a>

<a name="UseSnippet"></a>

Using Snippets in Charts

To use the snippet in a chart, put the name of the snippet inside square brackets where the snippet's contents will be substituted into the query:

select * from users where [user_is_real]

In a chart or view SQL editor, the snippet call will turn green when correctly referenced:

At any time, hover the mouse over the snippet to see the code it contains:

<a href="#top">Back to top</a>

<a name="SnippetSettings"></a>

Snippet Settings

<a name="Tags"></a>

Tagging a Snippet

To create a tag, click into the Tags textbox.

Enter the new tag name and click out of the textbox. The newly created tag will be added to the tags for the snippet and the tag list available for other snippets.

<a name="Description"></a>

Adding a Description

To add a description, click and type into the Description textbox. Once a description has been added, click outside of the text box to lock the description in place prior to saving. The description will show up with the snippet code when hovering over the snippet in the SQL Snippet search bar.

<a name="Owner"></a>

Changing a Snippet Owner

Changing the view owner can be done from the Owner dropdown. This allows other users to know who to ask questions about the snippet

<a href="#top">Back to top</a>

Looking for More?

Try our other documentation guides for guidance on topics like: