Select from a dynamic table name returned by databricks function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2024 07:37 AM
- I have a databricks function that returns a table_name
- I want to select from the table that is returned by this function. How can I make it work in SQL, something like this -
SELECT * FROM (SELECT test_func())
Currently this SELECT is returning a single row with the table name and not the contents of the table name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2024 08:46 AM - edited 03-30-2024 09:08 AM
Thanks @Retired_mod . This does not work in Databricks notebook, error attached. This looks like a SQL Server solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2024 09:46 AM - edited 03-30-2024 09:51 AM
I looked at this post
What I want is to replace the static table name with the table name passed as parameter (param_table_name). Is it possible?
CREATE OR REPLACE FUNCTION mydb.tbl_filter(a_val INT, param_table_name string)
RETURNS TABLE(a INT, b INT)
RETURN SELECT * FROM tbl_filter.param_table_name tf
WHERE tf.a = tbl_filter.a_val;