Tag Info

New answers tagged

3

Strictly speaking (T-SQL subroutine): No. Technically speaking (a means to abstract formulas to be defined once): Yes. Pragmatically speaking: It depends :). Here are the issues that are currently impeding you regarding restrictions on T-SQL functions: They cannot be declared dynamically They cannot access temporary tables They cannot be aggregate ...


3

No this isn't possible. A permanent TVF or view isn't an option due to the reference to #MyTempTable I've seen a connect item request for temporary views and agree sometimes they would be useful. This was closed as duplicate of one requesting Module-level table expressions. You might be able to rewrite as SELECT A, B, C, CASE ...


4

As per the documentation states: The NEXT VALUE FOR function is nondeterministic, and is only allowed in contexts where the number of generated sequence values is well defined. Below is the definition of how many values will be used for each referenced sequence object in a given statement: SELECT - For each referenced sequence object, a new value is ...


1

If you don't always want to pass all parameters, create a function with parameter defaults. The basic, simple form would be an SQL function without dynamic SQL: CREATE OR REPLACE FUNCTION func( _a int = NULL , _b text = NULL , _c text = NULL) RETURNS TABLE(...) AS $func$ SELECT ... FROM ... WHERE (speed = $1 OR $1 IS NULL) AND ...


1

You can use Dynamic queries. Here is a page about it. Check out about 2/3rds of the way down after "Example 40-1. Quoting Values In Dynamic Queries". But like it states, you need to be VERY careful. Doing this type of SQL creation on the fly can be a huge hole for SQL injection. http://www.postgresql.org/docs/current/static/plpgsql-statements.html


0

Even if extracting fields from a date would always produce results that could fit in an integer, according to the doc, extract doesn't directly work on a date type: The extract function retrieves subfields such as year or hour from date/time values. source must be a value expression of type timestamp, time, or interval. (Expressions of type date are ...


1

In the interests of learning how to fish, I have successfully compiled and installed a "Hello, World!" UDF (user-defined function) for MySQL found here. The hello_world.so file (after being complied with gcc -shared -o hello_world.so -I /usr/include/mysql hello_world.c) should be stored in /usr/lib/mysql/plugins/ with 755 permissions on Ubuntu linux systems. ...


1

Because the return values can be large or a decimal number. Double precision will accept a wide range of values Looking at other numeric types, you only have decimal which will have overhead: you don't know the return scale or precision needed beforehand so it would have to wide SELECT EXTRACT(SECOND FROM TIME '17:12:28.5'); Result: 28.5 SELECT ...


1

If you look at the GetFamilyTree code, there is nothing monitoring the tree height or any particular level. To compensate, I have a revised version of this code DELIMITER $$ DROP FUNCTION IF EXISTS `junk`.`GetFamilyTree` $$ CREATE FUNCTION `junk`.`GetFamilyTree` (GivenID INT,LevelLimit INT) RETURNS varchar(1024) CHARSET latin1 DETERMINISTIC BEGIN ...



Top 50 recent answers are included