Questions tagged [user-defined-functions]

A function provided by the user of a program or an environment most often for spreadsheet type applications or database applications. Use [custom-functions-excel] for Excel and [custom-function] for Google sheets. Specify a programming language tag as well: [google-apps-script], [javascript], [sql], [tsql], etc. as well as a tag for the application: [excel], [google-spreadsheet], [sql-server] etc.

In the context of a programming language or an environment, a User Defined Function (UDF) is a function that is created by a user to perform a specific task (as opposed to a function that is intrinsic to the environment, built into the programming language or environment).

Spreadsheet applications like Excel and Google Sheets calls these "custom functions".

Microsoft also uses the term User Defined Functions with . The tag may also be applicable. See What is the need for user-defined functions in SQL Server?

Use:

4875 questions
1
vote
1 answer

Dynamically return table with different columns in a User Defined Table Function.

There are several limitations between a SQL Server stored procedure and a user defined function. UDF's Can't use nondeterministic functions change the state of the database Return messages to the caller have any side effects A stored procedure…
JeffO
  • 7,957
  • 3
  • 44
  • 53
1
vote
2 answers

Replicate Google Sheets {array1; array2} function in Microsoft Excel as user defined function

In Google Sheets, I can use the ={range1;range2;...} notation to append multiple ranges into one as part of a formula. In Excel, it seems this functionality isn't available as a formula. I would like to create a user defined function to allow me to…
devlife
  • 13
  • 3
1
vote
0 answers

How to create a stored procedure to run a script in Snowflake?

I want to execute a SQL script on a schedule in Snowflake. There are several CTEs and a JavaScript UDF in my query. My idea is to Table the query of the result. Create one stored procedure Create a task to execute the procedure How can I create…
1
vote
2 answers

How do I make an Excel VBA Function that works when I reopen the document?

OK, I've just written a very simple VBA script that goes off and grabs the file size of a file found at a specified location (edit update code from dscarr): Public Function FileSize(path As String) As Variant On Error GoTo Err_FileSize: Dim…
ninesided
  • 23,085
  • 14
  • 83
  • 107
1
vote
1 answer

BigQuery User Defined Function Error - Unable to Call UDF In Query

I am trying to use a user defined function that I have created in my BQ dataset. Here is the UDF: CREATE OR REPLACE FUNCTION `project.dataset.CountHolidays`(START_DATE DATETIME, SLA INT64, OPERATION STRING) AS ( ( SELECT …
z.rubi
  • 327
  • 2
  • 15
1
vote
1 answer

Failure to serialize json to table row during Dataflow Job to stream data to BigQuery

I'm using a Dataflow Job template to stream data from a Pub/Sub Subscription to BigQuery. From each JSON file I need to transform the values and output multiple table rows at once to a BQ table. A simplified version of the JSON message arriving to…
1
vote
1 answer

Finding Next Odd or Next Even Value in a list of numbers

Given a list of numbers I am trying to find the next odd or even number from the list given a specified number. The specified number doesn’t have to be in the range. For ex: I am given number 406, I am suppose to find the next even or odd value from…
Shah
  • 11
  • 2
1
vote
0 answers

In a Pandas UDF, is it possible to return a Series containing nested lists?

I would like to create a Pandas UDF that returns a series containing a list of lists. This list represents the normalized pixel values of an image. Is it possible to return this datatype from a Pandas UDF? I tried adding ArrayType(FloatType()) to…
1
vote
2 answers

Use MySQL Query Execution Plan for Detecting SQL Injections

I have a project that requires we allow users to create custom columns, enter custom values, and use these custom values to execute user defined functions. Similar Functionality In Google Data Studio We have exhausted all implementation strategies…
1
vote
0 answers

Can a PandasUDF take in a series of type String and return a series of type Array?

I'm trying to use PandasUDF's to preprocess images. This involves converting from Base64 strings to NumPy arrays. I would like the PandasUDF to take in a series of type string, and return a series of type list (I can convert np array to list before…
1
vote
1 answer

Snowflake JSON to tabular

I was reading through the documentation of Snowflake and haven't found a solution yet so I come to you. I have a table in Snowflake which contains a variant column where I store JSON data. Do you know of a way to dynamically convert the results of a…
1
vote
1 answer

(JAVA) Spark SQL UDF with complex input parameter

I'm trying to use UDF with input type Array of struct. For example, let's say I have the following structure of data. This would all come from a single column from a table, from a single row. [ { "id": { "value": "23tsdag"}, "parser": { } …
Ethan Yim
  • 85
  • 1
  • 6
1
vote
2 answers

How to resolve error with SQL Scalar variable using GETDATE

I'm writing a scalar variable in SQL to define a season year (which starts halfway through a calendar year). It needs to change as the date changes i.e. 2021 for this date, on June 1 2022 then it should change to 2022. It's generating this error…
Mich
  • 13
  • 4
1
vote
2 answers

User-defined functions with multiple variables? / Function to operate on a range of named columns (instead of indexed by number)?

I frequently want to perform functions on a set or range of columns in a dataframe. Most commonly, I want to take the mean of a range of columns that share a common prefix (in this toy example, VarA., VarB., and VarC.: ID<-c(1:300) #participant ID…
geedlet
  • 143
  • 1
  • 8
1
vote
1 answer

What is Right way to get spark executing udf

As fas as I know , the spark use lazy computation meaning if the action is not called, nothing would ever never happen . And one way I know is using collect method get spark working , however when I read the article it says : Usually, collect() is…
Pro_gram_mer
  • 749
  • 3
  • 7
  • 20