cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Temporary view

y_sanjay
Visitor

Hi,
I wrote a query to create temp view in my catalog, query execution was successful and returned the result as 'OK' in SQL editor window. However, when I executed the command 'Show Tables' and' Select * {temp_view}', it's not identifying the view. What could have gone wrong?

2 REPLIES 2

mmayorga
Databricks Employee
Databricks Employee

hi @y_sanjay 

Thank you for reaching out.

Temporary views are only usable in the scope of the notebook or SQL session where you defined them, then  they are dropped after the session ends.  

You may want to use "SHOW VIEWS" instead that also shows temporary views, but again, in the same session to reflect the results; otherwise, it won't be visible.

I hope this helps!

szymon_dybczak
Esteemed Contributor III

Hi @y_sanjay ,

I guess that is somehow related to how sessions are managed within SQL Editor. For instance when I ran following queries in SQL Editor all at once it worked and I've got 3 result sets:

1) First result set with OK status - which means that my view was successfuly created

szymon_dybczak_0-1758743550688.png

2) Second result set associated with my SELECT * FROM employees view

szymon_dybczak_1-1758743602423.png

3) And the last one associated with SHOW VIEWS;

szymon_dybczak_2-1758743635801.png


Now, when I try to execute this code one statement at the time I've got the same error as you:

szymon_dybczak_3-1758743682924.png

Now, in the documentation they mentioned that temporary views are visible only to the session that created them and are dropped when the session ends. So that could suggest that in SQL Editor every query rans in new session or there is some kind of bug.

szymon_dybczak_4-1758743723931.png

Because if I try to execute the same kind of code on the same kind of compute within notebook - there's no such an issue:

szymon_dybczak_5-1758743885586.png

 

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local communityโ€”sign up today to get started!

Sign Up Now