create elt() in postgresql

create elt() in postgresql

ELT() is inbuilt in mysql.it returns str1 if N = 1, str2 if N = 2, and so on. Returns NULL if N is less than 1 or greater than the number of arguments

syntax:ELT(N,str1,str2,str3,…)

User defined function in postgresql for ELT().

syntax:
CREATE OR REPLACE FUNCTION elt(integer, text, text)
RETURNS text AS $$
SELECT CASE
WHEN $1 2 THEN NULL
WHEN $1 = 1 THEN $2
ELSE $3
END
$$ IMMUTABLE LANGUAGE SQL;

Leave a Reply


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.