In Databricks I can return a simple list of all function names with SHOW FUNCTIONS and I can return the description of one function with DESCRIBE FUNCTION function_name but if I want a list of all functions with the description how can I combine these functions?
I'm using Dbeaver to explore my Databricks database and I feel like the answer is to use Dynamic Parameter Binding https://dbeaver.com/docs/wiki/SQL-Execution/#dynamic-parameter-bindings
I have already enabled Anonymous SQL Parameters in the settings for my Databricks connection.
Somehow I need to loop through the output from SHOW FUNCTIONS and feed that in as the input for DESCRIBE FUNCTION function_name
Thanks for any help/tips!
I have a function in my sql query. when I want to use it in BIP. I can use only standard SQL.
but I noticed there are two more options which are (procedure call) and (Non Standard SQL).
How to run my query. by using those two options.
the funtion (No info how to use it): CREATE OR REPLACE FUNCTION get_exchange_rate (....etc.)
The query (to run it in BIP):
NVL(SUM(ABS(DECODE(SIGN(ACCTD_AMOUNT_DUE_REMAINING*
get_exchange_rate('USD', :P_CURRTO, a.TRX_DATE) ),-1,
ACCTD_AMOUNT_DUE_REMAINING*
get_exchange_rate('USD', :P_CURRTO, a.TRX_DATE) ,0))),0) CREDIT_AMOUNT,
I've got a PL/pgSQL function and I'm connecting to Postgres 12.x using Scala library called doobie which uses JDBC underneath. I'd like to understand if the whole call to the function will be treated as a single transaction? I've got default setting of autocommit.
The call to the function is simply:
select * from next_work_item();
All functions in PostgreSQL are always running in a single transaction, no matter what.
I recently had to generate a BQ table out of other BQ tables. The logic was rather involved and I ended up writing a complex SQL statement.
In Oracle SQL I would have written a PL/SQL procedure with the logic broken down into separate pieces (most often merge statements). In some cases I would encapsulate some code into functions. The resulting procedure would be a sequence of DML statements, easy to read and maintain.
However nothing similar exists for BQ. The UDF's are only temporary and cannot be stored within -say- a view.
Question: I am looking for ways to make my complex BQ SQL code more modular and readable. Is there any way I could accomplish this?
currently available option is to use WITH Clause
The WITH clause contains one or more named subqueries whose output acts as a temporary table which subsequent SELECT statements can reference in any clause or subquer
I would still consider User-Defined Functions as a really good option.
JS and SQL UDF are available in BigQuery and from what is known BigQuery team is working on introducing permanent UDF to be available soon
Meantime you can just store body of JS UDF as a js library and reference it in your UDF using OPTIONS section. see Including external libraries in above reference
October 2019 Update
The ability to use scripting and stored procedures is now in Beta.
So, you can send multiple statements to BigQuery in one request, to use variables, and to use control flow statements such as IF and WHILE, etc.
And, you can use procedure, which is a block of statements that can be called from other queries.
Note: it is Beta yet
BigQuery supports persistent user-defined functions. To get started, see the documentation.
For example, here's a CREATE FUNCTION statement that creates a function to compute the median of an array:
CREATE FUNCTION dataset.median(arr ANY TYPE) AS (
(
SELECT
IF(
MOD(ARRAY_LENGTH(arr), 2) = 0,
(arr[OFFSET(DIV(ARRAY_LENGTH(arr), 2) - 1)] + arr[OFFSET(DIV(ARRAY_LENGTH(arr), 2))]) / 2,
arr[OFFSET(DIV(ARRAY_LENGTH(arr), 2))]
)
FROM (SELECT ARRAY_AGG(x ORDER BY x) AS arr FROM UNNEST(arr) AS x)
)
);
After executing this statement, you can reference it in a follow-up query:
SELECT dataset.median([7, 1, 2, 10]) AS median;
You can also reference the function inside logical views. Note that you currently need to qualify the reference to the function inside the view using a project, however:
CREATE VIEW dataset.sampleview AS
SELECT x, `project-name`.dataset.median(array_column) AS median
FROM `project-name`.dataset.table
I know UDF in legacy sql, but UDF need you pass whole row into function, and return whole record, and UDF can't put into select section, this is not real function I need, Is Bigquery Legacy SQL can write function like Standard SQL? (can put into select or where section)
thanks :)
This functionality is only supported in Standard SQL (and as Elliott mentions in the comments, is unlikely to be added to Legacy SQL because it is being phased out).