# Creating and updating a temporary table in LookML

**URL:** <https://discuss.google.dev/t/creating-and-updating-a-temporary-table-in-lookml/164590>\
**Category:** Looker\
**Tags:** lookml\
**Created:** [August 26, 2024, 11:55pm UTC](https://discuss.google.dev/t/creating-and-updating-a-temporary-table-in-lookml/164590 "2024-08-26T23:55:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![JVFrancis](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/jvfrancis/32/97244_2.png) [@JVFrancis](https://discuss.google.dev/u/JVFrancis)\
**Post date:** [August 26, 2024, 11:55pm UTC](https://discuss.google.dev/t/creating-and-updating-a-temporary-table-in-lookml/164590/1 "2024-08-26T23:55:19Z")

</div>

I am trying to create/update table/view inside a SQL based derived\_table in LookML. Is that possible? I keep getting an error which prevents the creation of the PDT in Looker but the query statements run fine in BigQuery and the table/view gets created in the temp database. Can someone please help?

---

<div class="post-metadata">

**Author:** ![marcwo](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/marcwo/32/159417_2.png) [@marcwo](https://discuss.google.dev/u/marcwo)\
**Post date:** [August 27, 2024, 8:11am UTC](https://discuss.google.dev/t/creating-and-updating-a-temporary-table-in-lookml/164590/2 "2024-08-27T08:11:49Z")

</div>

Hello @JVFrancis

can you please elaborate what you are trying to achieve, whats the error you are receiving, and if possible, share some code here?

Thanks  
Marc

---

<div class="post-metadata">

**Author:** ![JVFrancis](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/jvfrancis/32/97244_2.png) [@JVFrancis](https://discuss.google.dev/u/JVFrancis)\
**Post date:** [August 27, 2024, 2:03pm UTC](https://discuss.google.dev/t/creating-and-updating-a-temporary-table-in-lookml/164590/3 "2024-08-27T14:03:29Z")

</div>

@marcwo Sure! I am trying to run a sequence of create/update queries to be used as a LookML view. The temp table “Parent” gets created when I run these queries in BigQuery but I get the error **“message”: “configuration.query.destinationTable cannot be set for scripts”, “status”: “INVALID\_ARGUMENT”** in the explore in Looker

Please see the code below,

declare counter int64;

set counter = 0;

create or replace temporary table Parent( OrgID int64 not null, OrgTypeID int64 not null, RootOrgID int64, CurrentOrgID int64 not null );

insert into Parent

select  
OrgID,  
OrgTypeID,  
case when OrgTypeID in (0, 1, 3) then OrgID else null end,  
ParentOrgID  
from Organization where OrgID \> 1;

repeat  
set counter = counter + 1;

update Parent rpo  
set  
RootOrgID = case  
when ans.OrgTypeID = 0 then ans.OrgID  
when rpo.OrgTypeID = 2 and ans.OrgTypeID = 1 then ans.OrgID  
when rpo.OrgTypeID = 4 and ans.OrgTypeID = 3 then ans.OrgID  
else null end,  
CurrentOrgID = ans.ParentOrgID  
from Organization ans  
where ans.OrgID = rpo.CurrentOrgID and rpo.RootOrgID is null;  
until not exists(select 1 from Parent where RootOrgID is null) or counter \> 15  
end repeat;

select \* from Parent  
order by 1;

---

<div class="post-metadata">

**Author:** ![marcwo](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/marcwo/32/159417_2.png) [@marcwo](https://discuss.google.dev/u/marcwo)\
**Post date:** [August 27, 2024, 2:31pm UTC](https://discuss.google.dev/t/creating-and-updating-a-temporary-table-in-lookml/164590/4 "2024-08-27T14:31:51Z")

</div>

Are you trying to create this using the _regular_ derived table syntax

```markdown
view: customer_order_summary {
  derived_table: {
    sql:
      YOUR SQL CODE
  }
}

```

Or have you tried using the [sql\_create](https://cloud.google.com/looker/docs/reference/param-view-sql-create) LookML syntax?

---

<div class="post-metadata">

**Author:** ![JVFrancis](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/jvfrancis/32/97244_2.png) [@JVFrancis](https://discuss.google.dev/u/JVFrancis)\
**Post date:** [August 27, 2024, 2:33pm UTC](https://discuss.google.dev/t/creating-and-updating-a-temporary-table-in-lookml/164590/5 "2024-08-27T14:33:11Z")

</div>

I am using the regular derived table syntax

---

<div class="post-metadata">

**Author:** ![JVFrancis](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/jvfrancis/32/97244_2.png) [@JVFrancis](https://discuss.google.dev/u/JVFrancis)\
**Post date:** [August 27, 2024, 2:45pm UTC](https://discuss.google.dev/t/creating-and-updating-a-temporary-table-in-lookml/164590/6 "2024-08-27T14:45:09Z")

</div>

I tried using sql\_create instead of sql in the LookML but I got the **"**

**Not found: Table us-ezl-dl-ingest-919726cd:looker\_scratch.LR\_8KE3O1724769551198\_topparenttable was not found in location us-east4"** error in the explore. topparenttable is the LookML view name.

---

<div class="post-metadata">

**Author:** ![JVFrancis](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/jvfrancis/32/97244_2.png) [@JVFrancis](https://discuss.google.dev/u/JVFrancis)\
**Post date:** [August 27, 2024, 3:13pm UTC](https://discuss.google.dev/t/creating-and-updating-a-temporary-table-in-lookml/164590/7 "2024-08-27T15:13:42Z")

</div>

I got it working by using the below code at the end of my derived\_table LookML for creating the topparenttable view as given in the [sql-create](https://cloud.google.com/looker/docs/reference/param-view-sql-create) documentation  
create or replace table ${SQL\_TABLE\_NAME} as (My final select query);  
select \* from ${SQL\_TABLE\_NAME} ;;  
Thanks a lot @marcwo Much appreciated!

---

<div class="post-metadata">

**Author:** ![marcwo](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/marcwo/32/159417_2.png) [@marcwo](https://discuss.google.dev/u/marcwo)\
**Post date:** [August 27, 2024, 3:15pm UTC](https://discuss.google.dev/t/creating-and-updating-a-temporary-table-in-lookml/164590/8 "2024-08-27T15:15:59Z")

</div>

Perfect, glad we got it working- have a good day!

Best

---

<div class="post-metadata">

**Author:** ![JVFrancis](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/jvfrancis/32/97244_2.png) [@JVFrancis](https://discuss.google.dev/u/JVFrancis)\
**Post date:** [August 27, 2024, 3:22pm UTC](https://discuss.google.dev/t/creating-and-updating-a-temporary-table-in-lookml/164590/9 "2024-08-27T15:22:16Z")

</div>

Thanks! Have a good day!
