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
38
votes
6 answers

Remote table-Valued Function Calls are not allowed

How can I make this work?Im running a table valued function from a remote linked server. i tried adding no lock to this 4 part naming but still i get the same error. Im using mssql-2008 select * from…
anonymous1110
  • 885
  • 4
  • 14
  • 28
36
votes
8 answers

What's a good way to check if two datetimes are on the same calendar day in TSQL?

Here is the issue I am having: I have a large query that needs to compare datetimes in the where clause to see if two dates are on the same day. My current solution, which sucks, is to send the datetimes into a UDF to convert them to midnight of…
Eric Z Beard
  • 37,669
  • 27
  • 100
  • 145
35
votes
1 answer

How to create a udf in PySpark which returns an array of strings?

I have a udf which returns a list of strings. this should not be too hard. I pass in the datatype when executing the udf since it returns an array of strings: ArrayType(StringType). Now, somehow this is not working: the dataframe i'm operating…
makansij
  • 9,303
  • 37
  • 105
  • 183
35
votes
3 answers

SparkSQL: How to deal with null values in user defined function?

Given Table 1 with one column "x" of type String. I want to create Table 2 with a column "y" that is an integer representation of the date strings given in "x". Essential is to keep null values in column "y". Table 1 (Dataframe df1): +----------+ | …
34
votes
2 answers

Execute table-valued function on multiple rows?

Given a table-valued function such as dbo.Split() from "T-SQL: Opposite to string concatenation - how to split string into multiple records", how do I pass multiple rows as arguments? This works: SELECT * FROM dbo.Split (',', (SELECT myColumn FROM…
Sören Kuklau
  • 19,454
  • 7
  • 52
  • 86
34
votes
1 answer

OOo/LibreOffice UNO / Java: How to get calling spreadsheet cell of a calc function?

In an UNO extension for OpenOffice/LibreOffice Calc (Spreadsheet), written in Java, how can you determine the calling cell inside the implementation of a UDF (spreadsheet function)? Remarks In Excel/VBA this is possible via Application.Caller The…
Christian Fries
  • 16,175
  • 10
  • 56
  • 67
34
votes
5 answers

How do I test a Table-Valued Function in SQL Server Management Studio?

I've never worked with Database Functions, but my current project requires it. I need to put a common sql query into a function so we don't have to type it out in our code hundreds of times. I've got the function created, but I don't know how to…
Jeff
  • 343
  • 1
  • 3
  • 5
33
votes
4 answers

Function Overloading and UDF in Excel VBA

I'm using Excel VBA to a write a UDF. I would like to overload my own UDF with a couple of different versions so that different arguments will call different functions. As VBA doesn't seem to support this, could anyone suggest a good, non-messy way…
Patrick
  • 596
  • 1
  • 6
  • 15
33
votes
4 answers

How to add levenshtein function in mysql?

I got the code for Levenshtein distance for MySQL from http://kristiannissen.wordpress.com/2010/07/08/mysql-levenshtein/(archive.org link), but how to add that function in MySQL? I am using XAMPP and I need it for search in PHP.
Sandesh Sharma
  • 1,064
  • 5
  • 16
  • 32
32
votes
2 answers

Is it possible to define a local function in a TSQL query?

I have a complex expression calculating a value from a date that I have to use on multiple date columns. Can I define a temporary local function in my query to avoid copy and pasting this expression. ? like: create MyLocalFunc(@ADate datetime)…
Francesca
  • 21,452
  • 4
  • 49
  • 90
30
votes
1 answer

Defining a UDF that accepts an Array of objects in a Spark DataFrame?

When working with Spark's DataFrames, User Defined Functions (UDFs) are required for mapping data in columns. UDFs require that argument types are explicitly specified. In my case, I need to manipulate a column that is made up of arrays of objects,…
29
votes
2 answers

Why is my custom MySQL function so much slower than inlining same in query?

I repeatedly use this SELECT query to read unsigned integers representing IPv4 addresses and present them as human readable dotted quad strings. SELECT CONCAT_WS('.', FLOOR(ip/POW(256,3)), MOD(FLOOR(ip/POW(256,2)), 256), MOD(FLOOR(ip/256),…
Day
  • 9,465
  • 6
  • 57
  • 93
29
votes
2 answers

T-SQL: How Do I Create A "Private" Function Inside A Stored Procedure

Okay so I'm writing a SQL Server 2008 Stored Procedure (maintenance script). In doing so, being a good boy I've done plenty of error handling, checking rowcounts, printing output messages, etc But in doing this, I've found myself writing over and…
RPM1984
  • 72,246
  • 58
  • 225
  • 350
28
votes
4 answers

Why is TRY-CATCH block not allowed inside UDFs?

Why doesn't SQL Server support TRY-CATCH blocks inside UDFs? If we're talking about scalar UDFs, which are mostly used for calculations and conversations, this block should be heavily used, but we don't have it. Also, what workarounds do you use for…
Fedor Hajdu
  • 4,657
  • 3
  • 32
  • 50
27
votes
2 answers

How can I pass extra parameters to UDFs in Spark SQL?

I want to parse the date columns in a DataFrame, and for each date column, the resolution for the date may change (i.e. 2011/01/10 => 2011 /01 if the resolution is set to "Month"). I wrote the following code: def convertDataFrame(dataframe:…
DarkZero
  • 2,259
  • 3
  • 25
  • 36