Load data into Snowflake using a SQL statement
Before I could demo row level security in Tableau, I had to get the sample data into Snowflake from scratch using nothing but a SQL statement.
- Snowflake database names can't contain spaces, so use underscores when creating one through the interface
- If you don't own the database you need to set up the relevant role privileges before creating tables and inserting data
- In the Snowflake worksheets you must specify the target database and schema in the top-right context before running SQL, or it will error
- Highlighting just the SQL you want and clicking run is a safer habit than executing an entire script at once
- You can preview loaded rows either via the preview data button or by right-clicking the table in the object explorer
0:00Hey it's Tim here. In Tableau 21.4 there's
0:02a feature that I wanted to demo which shows
0:04row level
0:04security. Now in order to demo that I
0:07needed to do two things set up a virtual
0:09connection to a
0:09database and then show off the row level
0:12permissions. But in order to do that I
0:14needed to load the data
0:15into Snowflake. Now Tableau actually
0:17created some sample data for this demo. So
0:20you can see it here
0:21I've actually got it in my Dropbox folder
0:23you can see where it's coming from here but
0:24essentially
0:25it's a SQL statement that creates a table
0:27then loads the data then creates another
0:30table then
0:30loads that data and you can see there's a
0:32lot of data here it's all been sort of bun
0:34ged into the
0:35SQL statement and I think it creates three
0:37or four data sets. If I just keep going
0:39down here
0:40we'll pretty much see another one we just
0:42saw another one there just sort of flash by
0:44if we go
0:44back up we also have here the orders table
0:46then we have all the orders and so on and
0:48so forth. So
0:50essentially what I'm going to show you in
0:52this video is how to load sample data into
0:54Snowflake.
0:54I'm going to need to do everything from
0:56scratch and so that's what I'm going to
0:57show you okay
0:58let's get stuck in. So here we are we're in
1:00Snowflake now I'm just using the sort of
1:02online
1:03interface here I'm not using any sort of
1:04database tools if you use one of those that
1:06's totally fine
1:07everything is pretty much going to work the
1:09same I'm just doing this to keep things
1:11nice and simple.
1:12So what I first need to do is to create a
1:14demo database I don't actually have one set
1:16up I've
1:16got mostly utility databases here some
1:20sample databases and also my database for
1:23my youtube
1:24channel so that's called TNMD5-TRAN because
1:275-TRAN pumps some data into that. So first
1:29we'll need to
1:30go to the databases section and create a
1:32database and we can call this Tableau demo
1:36database. Now
1:38for those of you who are watching this and
1:40know how to create a database here you'll
1:42know there's
1:42going to be an issue here when I click
1:43finish and that is it doesn't like the
1:45spaces between
1:46the names so we'll go ahead and do an
1:48underscore just to make sure that meets the
1:50condition that's
1:51required we can call this like just put a
1:54comment here so a demo db that's going to
1:57be all I need
1:58go ahead and hit create and boom we've got
2:00it there. Now what we would typically do
2:02now is set
2:02up privileges for a particular role or
2:05whatever but I'm the only one on this
2:06database so I have
2:08access to everything so if you don't have
2:09access to everything you need to pay
2:11attention to this
2:11make sure you set up the relevant
2:13privileges so that you can then switch into
2:15the role that you're
2:15going to be using for analytics or maybe
2:17your users are going to be using and make
2:19sure they can do
2:20this themselves but other than that you can
2:22just pretty much go ahead and get stuck in.
2:25Now once
2:25I've done this I'm actually going to do the
2:27rest using the worksheets capability so I
2:28'll go over
2:29to the worksheets capability and if I click
2:31on this little refresh button let me just
2:34click on
2:34this arrow here you'll see that it will
2:36refresh the window and I'll actually see my
2:38new table
2:38that I've created there there it is Tableau
2:41demo database and if we open this up and go
2:43into public
2:43you can see we have no tables or views in
2:45this schema so we need to create some views
2:48so let's
2:48go ahead and go to the very top of the SQL
2:50statement let me just go right to the top
2:53this
2:53is going to take me a little while let's
2:55just go all the way up here and you've got
2:56the first sort
2:57of SQL statement we can run now I'm just
3:00going to copy this section of it copy it
3:02from where I'm in
3:03VS code go to this particular page and
3:06paste it in and now we have that SQL so
3:08what the SQL is going
3:10to do is essentially just create the
3:11framework where we're going to load the
3:13data into so it
3:14just creates a table but it doesn't load
3:16any real data into it so what I can do is I
3:18can just run
3:19this whole entire SQL statement but I've
3:21gotten into the habit of highlighting what
3:23I want to run
3:24and then selecting run okay and so if I go
3:26to do this you'll hit run and it will
3:28complain
3:28essentially it's complaining because I
3:30haven't actually specified these parameters
3:32over here
3:33on the top right hand side so let's go
3:35ahead and select the relevant database let
3:37's go ahead here
3:38and select Tableau demo database it's now
3:41public everything is pretty much good to go
3:43and now if
3:43I go and do the same thing and I hit run
3:45you'll see that this actually works and it
3:48completes
3:48successfully it took us 165 milliseconds
3:51essentially and I'm using the small
3:54warehouse
3:54here I'm not using anything sort of
3:56powerful this is just sort of a standard
3:58capability I can double
3:59check that that table now exists by again
4:01hitting the little view over here refresh
4:03it now and you
4:04can see my employees table does exist and
4:07it has zero rows I can see that just there
4:09on the
4:09snowflake interface so now we're pretty
4:11much good to go and we're ready to load
4:12some real data let's
4:14go back to vs code and we can go to this
4:16little sort of area now they've put some
4:19sort of stuff
4:20in here so it says lock tables employees
4:22right we don't actually need that for this
4:24particular
4:24use case or for this particular setup that
4:27I'm running all I need is this SQL here
4:29that actually
4:29does the job of inserting the data so let's
4:31let's go ahead and slowly scroll down
4:33before we get to
4:34the next data set here on line 35 I'm going
4:36to copy that and when I bring it back in
4:38here I'm
4:39just going to copy it just a little bit
4:41below let's just go a few lines and paste
4:42it in here
4:43and you can see insert into employees and
4:46it's this really wide data set here and
4:48basically
4:49every single bit of information has just
4:51been pasted into that little area it's like
4:53an array
4:53in in web development or something like
4:55that but we're pretty much good to go now
4:57of course I need
4:57to highlight this and now that I've
4:59highlighted it I need to run it's kept all
5:01my variables from
5:02before so if I needed to change this for
5:04whatever reason maybe some people have the
5:06ability to create
5:07data and then some people have the ability
5:09to put data in and then some people have
5:11the ability to
5:12read data if you needed to change those you
5:14'd need to sort of go up here and change
5:16those permissions
5:17but nonetheless we're going to just select
5:19this line here line 25 and hit run and you
5:22'll get the
5:22SQL sort of display to you ask you again
5:24are you sure you want to do this you can
5:26actually copy the
5:27SQL in case you're not sure hit run and
5:29that will complete 427 milliseconds so that
5:32works pretty
5:33really well and what we can do we can again
5:35go up here to refresh then we should check
5:37this table
5:38and we should see some rows so let's go
5:40ahead and do that let's hit refresh this
5:43will refresh we'll
5:44hit the employees and there we have nine
5:46rows if you want to see a preview of this
5:48data there's a
5:48couple ways to do this there's this button
5:50right here where you can hit so let's go
5:52ahead and do
5:53that let's hit preview data and you'll see
5:54our preview loads here at the bottom so
5:56that's pretty
5:57much to the data that we just loaded and
5:59then if you want to do another way if you
6:00actually go to
6:01right here and right click you can also
6:03select the preview data option there and
6:04you're pretty much
6:05good to go so that's how i'm going to load
6:07the sample data for this specific demo in
6:10tabla i just
6:10wanted to show sort of the behind the
6:12scenes uh set up for that and hopefully you
6:14find it useful
6:15for learning how to load sample data that
6:18maybe you've got as a sql statement uh into
6:20your own
6:21sample database so you can do some tests
6:23and test out new features thanks for
6:24watching i'll catch
00:00 - Intro00:59 - Setting up02:25 - Using worksheets to run the SQL03:26 - Running the SQL to create the Table04:20 - Insert values04:57 - Load the data into the create tableFollow me on Twitter: https://twitter.com/TableauTimMy recording gear & what’s on my desk. https://kit.co/TableauTim/desk-setup My website: https://www.tableautim.com/My place of work: https://www.theinformationlab.co.uk/