Questions tagged [sql-function]

A function defined in a relational database system. Most RDBS's include numerous built-in functions and also allow for the creation of additional custom functions.

908 questions
3
votes
5 answers

GROUP BY with SUM without removing empty (null) values

TABLES: Players player_no | transaction_id ---------------------------- 1 | 11 2 | 22 3 | (null) 1 | 33 Transactions id | value | ----------------------- 11 | 5 22 | 10 33…
krzakov
  • 3,871
  • 11
  • 37
  • 52
3
votes
2 answers

Passing parameters to a SQL view

I have a SQL view, and I want to filter it using parameters passed to it. I was thinking about creating a stored procedure, however, after some research, I came to the conclusion that this is not possible. Other similar threads suggested either…
David
  • 1,192
  • 5
  • 13
  • 30
3
votes
1 answer

Self joining a table n times

I'm trying to find a biological "find core genome of a given set of organisms" problem. Essentially, given a list of organisms, find all genes that are common to them. To abstract away biology, you can think of find all colours that are favourite…
player87
  • 1,781
  • 1
  • 14
  • 21
3
votes
1 answer

Understanding COUNT behavior in queries vs. EXPLAIN vs. functions

I am curious to understand (and perhaps improve) an issue I am having with PostgreSQL 9.6. Names simplified but everything else is taken from a psql session. I start with a materialized view, mv. First, I create two simple functions: CREATE FUNCTION…
rg6
  • 329
  • 2
  • 10
3
votes
1 answer

How to call a function in another Function

I need to write a script that creates and calls a function named fnItemTotal that calculates the total amount of an item in the OrderItems table (discount price multiplied by quantity). To do that, this function should accept one parameter for the…
Daniel Stallard
  • 69
  • 1
  • 1
  • 5
3
votes
1 answer

PostgreSQL: SELECT a function on all items in an array

Consider a table with the following rows: id | bigint polygons | geometry(Polygon,4326)[] SELECT-ing the polygons row returns an array of unreadable binary data: SELECT polygons FROM some_table WHERE…
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
3
votes
3 answers

SQL - Find all UPPER CASE strings

Is there a way i can get all the uppercase strings in column from a table. Like creating a function? Is it possible to perform case-sensitive queries? In particular, I'd like to find all strings in a certain column that are in upper case. This is…
AndroidAL
  • 1,111
  • 4
  • 15
  • 35
3
votes
2 answers

Postgres function returning a row as JSON value

I am pretty new to PG, and trying to convert from MSSQL. I am working on a function that will return JSON results. This one works: Create Or Replace Function ExampleTable_SelectList() Returns JSON As $$ Select…
Arotae
  • 103
  • 1
  • 8
3
votes
1 answer

SQL UDF to return an array of dates

I have currently written a small UDF (Table Value Type) to return a table of dates between a start and end date. Start and End dates are already retrieved from another table. Start_End_Table WeekNumber | Start Date | End Date Function: CREATE…
bonCodigo
  • 14,268
  • 1
  • 48
  • 91
3
votes
1 answer

PostgreSQL function/view acting on CTE results?

I am writing a postgresql view that uses some complex logic to generate rows of data. It requires that I perform the same set of steps on two sets of data derived from results of querying two different tables. Is it possible to write a function that…
3
votes
2 answers

How is date conversion being done in sql server

I have a query like the one described below. select CAST(0x83360B00 AS Date) When I run this query in SQL server, I am able to get result in date format as: 2012-12-15 All I want to know is how this is being generated. Thanks in advance.
vstandsforvinay
  • 138
  • 1
  • 11
3
votes
1 answer

SqlFunctions.StringConvert doesn't work with doubles

I have something like that in code SqlFunctions.StringConvert( (double?) x.Latitude) but it returns an integer always although it has a latitude value. any help?
Mohamed Naguib
  • 1,720
  • 6
  • 23
  • 32
3
votes
3 answers

ISNULL/COALESCE counterpart for values that are not NULL

Is there a function that is similar to COALESCE but for values that are not NULL? I need to replace a return value of a scalar-valued-function with another value if it returns the string literal N/A. If it would return NULL i could use: SELECT…
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
3
votes
1 answer

SQL Stuff Function with Variable in SQL Server

I am trying to generate an Pivot table with SQL (SQL Server 2008). To get the column list I am using stuff function which works great if we use it with SQL. Although due to dynamic nature of Pivot structure (selection by user) I want to make column…
user2739418
  • 1,623
  • 5
  • 29
  • 51
3
votes
1 answer

How to split a single row into multiple rows in SQL

I have a table which looks as follows..it has multiple columns for different latencies Date API Latency1_Avg Latency1_Min Latency1_Max Latency2_Avg Latency2_Min Latency2_Max ---- --- ------------ ------------ ------------ ------------…
user330612
  • 2,189
  • 7
  • 33
  • 64