stored-functions

SQL Server - where is “sys.functions”?

别来无恙 提交于 2019-12-17 15:21:48
问题 SQL Server 2005 has great sys.XXX views on the system catalog which I use frequently. What stumbles me is this: why is there a "sys.procedures" view to see info about your stored procedures, but there is no "sys.functions" view to see the same for your stored functions? Doesn't anybody use stored functions? I find them very handy for e.g. computed columns and such! Is there a specific reason sys.functions is missing, or is it just something that wasn't considered important enough to put into

How to shuffle array in PostgreSQL 9.6 and also lower versions?

对着背影说爱祢 提交于 2019-12-14 03:55:27
问题 The following custom stored function - CREATE OR REPLACE FUNCTION words_shuffle(in_array varchar[]) RETURNS varchar[] AS $func$ SELECT array_agg(letters.x) FROM (SELECT UNNEST(in_array) x ORDER BY RANDOM()) letters; $func$ LANGUAGE sql STABLE; was shuffling character array in PostgreSQL 9.5.3: words=> select words_shuffle(ARRAY['a','b','c','d','e','f']); words_shuffle --------------- {c,d,b,a,e,f} (1 row) But now after I have switched to PostgreSQL 9.6.2 the function stopped working: words=>

MySQL query slow because of ORDER BY with Stored Functions

Deadly 提交于 2019-12-14 03:16:58
问题 My query goes from 15 seconds to 0.05 seconds when I remove the ORDER BY in the following query: simplified version: SELECT field1, fiedl2, field 3, FUNC1(1, 2) AS score1, FUNC2(1, 2) AS score2, FUNC3(1, 2) AS score3, FUNC4(1, 2) AS score4 FROM table WHERE field1 = 1 ORDER BY (score1 * 1 + score2 * 2 + score3 * 2 + score4 * 4) DESC; I have a couple of stored functions that calculate sub-scores. Except I have to order the result based on the total score. In the ORDER BY I use * 2 to add some

Stored function with temporary table in postgresql

穿精又带淫゛_ 提交于 2019-12-13 15:27:13
问题 Im new to writing stored functions in postgresql and in general . I'm trying to write onw with an input parameter and return a set of results stored in a temporary table. I do the following in my function . 1) Get a list of all the consumers and store their id's stored in a temp table. 2) Iterate over a particular table and retrieve values corresponding to each value from the above list and store in a temp table. 3)Return the temp table. Here's the function that I've tried to write by myself

Once again: Stored Procedure vs. TV-UDF [closed]

懵懂的女人 提交于 2019-12-13 09:23:14
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . I know, this was discussed several times (most discussions are some years back...). But - looking through these discussions - I get the feeling, that there is a broadly spread common sense which is simply wrong: TV-UDFs are bad in performance. Many people prefer SPs to

SELECT: Group by function result

让人想犯罪 __ 提交于 2019-12-13 04:05:36
问题 I have a stored function that calculates the status of an entity (this status is NOT an attribute of the entity but needs to be calculated). Within a SELECT statement, I want to know how many elements have which status. For now, I got the following: SELECT my_function(entity_id) AS status, COUNT(*) FROM some_table GROUP BY my_function(entity_id) -- entity_id is a column of some_table ORDER BY status; This works but I find it quite ugly to repeat the function call within the GROUP BY statement

Postgres 8.3 Query full function definition using a query

拥有回忆 提交于 2019-12-13 03:57:15
问题 Is it possible to be able to retrieve the full function definition (with parameters etc) using a SQL query? 回答1: This function or view (doing similar things) works with Postgres 8.3. CREATE AGGREGATE public.textcat_all( basetype = text, sfunc = textcat, stype = text, initcond = '' ); CREATE OR REPLACE FUNCTION public.getfunctionddl(functionOid oid) RETURNS text AS $BODY$ DECLARE funcschema text; funcname text = NULL; paranames text; paramodes text; paratypes text; paraintypes text; function

Stored Function - Sending/Receiving Boolean - BD

断了今生、忘了曾经 提交于 2019-12-13 02:17:45
问题 Found the solution, see bellow* I'm trying to execute a stored function, via SimpleJdbcCall (using java + jpa) but I can't execute, it shows: [Request processing failed; nested exception is org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{? = call PK_BACKOFFICE.SET_PROFESSIONAL(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}]; SQL state [null]; error code [17004]; Invalid column type; nested exception is java.sql.SQLException: Invalid column

Include all functions in the php file I need or just the functions I need?

不羁的心 提交于 2019-12-12 08:54:53
问题 So here is what I want to do. The first option is to write each function in different php file each one and then include all of them in a php file that is called include functions.php and whenever I create a new page , let's say index.php I just include "functions.php"; Why do I need to do that? Because I'll just have to include only one file and all the functions will be included. Now the problem probably will be the server load. I'm not sure how much uncalled functions affect the

Variable Table Name MySQL Stored Function

你说的曾经没有我的故事 提交于 2019-12-12 05:28:50
问题 I have several MySQL tables that maintains a tree structure of records. Each record have an ID and a Parent field. I want to write a stored function to get the parent ID, given a record ID. The following is my first attempt, and it's incorrect. My problem is I do not know how to use variable table name. delimiter $$ create function parent( tableName varchar(15), nodeId int ) returns int begin declare p int; select parent into p from tableName where id=nodeId; return p; end$$ Please help.