Sha256: 32c3de6b250a858788b96f9974eed5fda68f55355ee6587333df7a5538f6cf87

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

/* Taken from ultrasphinx */

/* http://osdir.com/ml/db.postgresql.admIN/2003-08/msg00057.html */

CREATE FUNCTION MAKE_CONCAT_WS() RETURNS text AS '
declare
  v_args int := 32;
  v_first text := ''CREATE FUNCTION CONCAT_WS(text,text,text) RETURNS text AS ''''SELECT CASE WHEN $1 IS NULL THEN NULL WHEN $3 IS NULL THEN $2 ELSE $2 || $1 || $3 END'''' LANGUAGE sql IMMUTABLE'';
  v_part1 text := ''CREATE FUNCTION CONCAT_WS(text,text'';
  v_part2 text := '') RETURNS text AS ''''SELECT CONCAT_WS($1,CONCAT_WS($1,$2'';
  v_part3 text := '')'''' LANGUAGE sql IMMUTABLE'';  
  v_sql text;
  
BEGIN
  EXECUTE v_first;
  FOR i IN 4 .. v_args loop
    v_sql := v_part1;
    FOR j IN 3 .. i loop
      v_sql := v_sql || '',text'';
    END loop;

    v_sql := v_sql || v_part2;

    FOR j IN 3 .. i - 1 loop
      v_sql := v_sql || '',$'' || j::text;
    END loop;
    v_sql := v_sql || ''),$'' || i::text;

    v_sql := v_sql || v_part3;
    EXECUTE v_sql;
  END loop;
  RETURN ''OK'';
END;
' LANGUAGE 'plpgsql';

SELECT MAKE_CONCAT_WS();

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
minisphinx-1.0.1 lib/mysqlcompat/concat_ws.sql
minisphinx-1.0.0 lib/mysqlcompat/concat_ws.sql