Updating Brand New SQL Table
What I'm trying to do with this sql data flow is to add to my data two additional columns based on one of the metrics in the origial input. Specifically, take DMA data and get a state and region column. But I'm running into issues.
I planned to do this by editing the original data, create a new table with the desired columns, and then full outer join the tables. The first transform updates a column in the source. That's fine. But I'm having trouble with my new table. Below are a few attempts to get things to work based on browsing forms. The bolded lines are where Domo tells me I'm getting errors.
V1
Create Table blog_dma_state_region
Select RIGHT(`Metro`, 2) AS State, `Metro`
Alter Table blog_dma_state_region
ADD US_Region varchar(255)
INSERT INTO blog_dma_state_region (US_Region)
VALUE ("Unknown")
V2
Create Table blog_dma_state_region
Select RIGHT(`ga_blog_dma_agg`.`Metro`, 2) AS State, `Metro`
Alter Table blog_dma_state_region
ADD US_Region Varchar(250) DEFAULT 'Unknown' NOT NULL
V3
Create Table blog_dma_state_region
Select RIGHT(`ga_blog_dma_agg`.`Metro`, 2) AS State, US_Region, `Metro`
UPDATE blog_dma_state_region
Set US_Region = CASE WHEN IN ('TX','OK','AZ','NM') Then 'Southwest'
.
.
.
The errors are all the same - my syntax. Which is getting pretty frustrating because I don't know how UPDATE (table) is a syntax error. And because it's getting caught at the same place (despite successfully updating my input in a different transform for this flow), I'm wondering if the issue here is because I'm creating a new table and then trying to edit it in the next step.
Is this even the right way to go about things? Should my CASE WHEN be in the CREATE NEW TABLE portion? And if so, how would that look? Do I need to split this? Create the table, generate an output, and then in a different transform update it?
Best Answer
-
Table changes such as adding fields and indexes must be done in their own transforms and you need to uncheck the box for 'Generate Output Table'. The other way to accomplish the table creations and alters would be to create a procedure and then call that procedure from another transform.
If I understand what you are trying to accomplish may I recommend the mySQL transform below which does not require the creation of another table to join.
select right(`Metro`, 2) as State
, `Metro`
, case when right(`Metro`, 2) in('TX','OK','AZ','NM') then 'Southwest'
when right(`Metro`, 2) in('PA','NJ','NY') then 'Northeast'
else 'Unknown'
end as US_Region
from `ga_blog_dma_agg
-----------------
Chris0
Answers
-
Table changes such as adding fields and indexes must be done in their own transforms and you need to uncheck the box for 'Generate Output Table'. The other way to accomplish the table creations and alters would be to create a procedure and then call that procedure from another transform.
If I understand what you are trying to accomplish may I recommend the mySQL transform below which does not require the creation of another table to join.
select right(`Metro`, 2) as State
, `Metro`
, case when right(`Metro`, 2) in('TX','OK','AZ','NM') then 'Southwest'
when right(`Metro`, 2) in('PA','NJ','NY') then 'Northeast'
else 'Unknown'
end as US_Region
from `ga_blog_dma_agg
-----------------
Chris0 -
Thanks, cwolman!
Knowing those changes need to be seperate is helpful, and your code below simplify things so thanks for that!
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 738 Beast Mode
- 57 App Studio
- 40 Variables
- 685 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 124 Manage
- 121 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive