Skip toΒ content

dbt Cloud: Environment Variables Demo

3 mins

View Comments and Reply

Transcript

Show Transcript

Hey folks, this is Sun speaking here, and I'm gonna give you a demo of how to create a dynamic database variable depending on a certain sub folder.

And so the problem I'm trying to solve for is, let's say I have, you know, models within my staging sub folder, um, and I wanna make sure that they're kind of like quarantined, so to speak, and they go into their own respective, you know, database.

And so, for example, I want everything that's materialized as a table or view here to land in my staging, you know, uh, database or in this case I'll just name it, um, whatever, some demo as a generic example.

And now the next thing is how do I make sure I can do that elegantly, um, without either hard coding it?

And how do I use something called environment variables? So step one is you have to open up your D P T project animal file.

I have that open right here. I already have this configured online 62. And right now I'm gonna do this. I'm gonna save that.

Next thing I need to do is, uh, let's just pretend we're starting from the homepage here. I go to deploy, I go to environments, I click on environment variables.

I'm gonna widen this up. And I name a variable called DPT Dynamic Database, and I make sure it defaults to mys demo development database for whatever reason.

I can edit that later if I want to, but I'm not for the purposes of this demo. From there, I add in my variable here using this syntax, make sure it's surrounded by single quotes and double quotes are within, I defaulted to some demo just in case this environment variable doesn't exist as a defense mechanism.

From there, I am going to do, I'll do this C stage orders, I am going to run this, and then it should pick up my environment variable over here and land that in thes demo database instead of the default.

And you notice there sung demo, you're probably wondering, hey, like what if you're, this is smoke and mirrors and, and sung your, this is always the default.

I'll show you another example with my first model. I'll run this and let's see what this defaults to instead. Go back up here, wait for this to run, go over here.

I'm gonna click on details, You know, to here, here you defaulted to the analytics database instead. And you're probably wondering, Hey song, how did you default that there, just when I set up my regular development environment over here, where, oh, excuse me, Oh, nevermind.

This is in the regular Snowflake connection, but let me actually show you go here. I'm gonna go to Sun Labs and over here, based off the default Snowflake connection that defaults to this database.

And that's it. So in summary, in order to dynamically change the database, your tables and views materialize in, use an environment variable and set that up over here within DPT Cloud.

And that's all you gotta do. All right, see ya.

Transcript

More than 21 million people across 200,000 companies choose Loom

My teammates and I love using Loom! It has saved us hundreds of hours by creating informative video tutorials instead of long emails or 1-on-1 trainings with customers.
Erica Goodell

Erica GoodellCustomer Success, Pearson

Loom creates an ongoing visual and audible experience across our business and enables our employees to feel part of a unified culture and company.
Tyson Quick

Tyson QuickCEO, Postclick

My new daily email habit. Begin writing an email. Get to the second paragraph and think 'what a time suck.' Record a Loom instead. Feel like 😎.
Kieran Flanagan

Kieran FlanaganVP of Marketing, HubSpot

Loom amplifies my communication with the team like nothing else has. It's a communication tool that should be in every executive's toolbox.
David Okuinev

David OkuinevCo-CEO, Typeform

My teammates and I love using Loom! It has saved us hundreds of hours by creating informative video tutorials instead of long emails or 1-on-1 trainings with customers.
Erica Goodell

Erica GoodellCustomer Success, Pearson

Loom creates an ongoing visual and audible experience across our business and enables our employees to feel part of a unified culture and company.
Tyson Quick

Tyson QuickCEO, Postclick