This draft documentation may be incomplete or inaccurate, and is subject to change until this release is generally available (GA).

Snippets

Introduction

Snippets allow you to share small, reusable bits of SQL with your team.

Demo

Creating your first Snippet

To create a snippet, select command / control + k, and search for "Create snippet".

Working with dates is a good example. Consider this snippet we use at SeekWell which creates three date formats from a timestamp.

date_trunc('day', {{column_name}})::date as "{{alias}}_day",
date_trunc('week', {{column_name}})::date as "{{alias}}_week",
date_trunc('month', {{column_name}})::date as "{{alias}}_month"
Created on date

Once you type {{, you’ll see the variable added to "Defaults". Here you can add a commonly used value for the variable (for example, created_on).

Variables are optional, not adding variables will create a "static snippet".

Navigation

  • To create a snippet, select command / control + k, and type "Create snippet".

  • To use a snippet from a block, select command / control + ; (semicolon).

  • To view / edit / delete your snippets, select command / control + k, and type "View snippet".

    View snippets

Library

SnippetLibrary

Name Tags SQL

addSubSelect

ansi

(select
{{group_by_col}},
max({{max_col}}) max_{{max_col}}
from
{{table}}
group by 1) as max_{{table}}

dayWeekMonth

postgres

date_trunc('day', {{column_name}})::date::text as "{{alias}}_day",
date_trunc('week', {{column_name}})::date::text as "{{alias}}_week",
date_trunc('month', {{column_name}})::date::text as "{{alias}}_month"

addWith

postgres

with {{alias}} as (
select
from {{table_name}}
)

Days between two dates

postgres

now()::date - some_date::date

Suggest a snippet here.


Was this page helpful?