 $$ LANGUAGE plpgsql;
 
 
-CREATE OR REPLACE FUNCTION fn_fuzzy_search_song( in_query tsquery )
-    RETURNS TABLE( match text, match_type text )
+CREATE OR REPLACE FUNCTION fn_fuzzy_search_song( in_query TSQUERY )
+    RETURNS TABLE( match TEXT, match_type TEXT )
     AS $$
 BEGIN
     RETURN QUERY

$$ LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION fn_get_songs_by_query( in_query tsquery )
    RETURNS SETOF integer
    AS $$
BEGIN
    RETURN QUERY
        SELECT song
          FROM song
         WHERE to_tsvector( 'english', coalesce( artist, '' ) || ' ' || coalesce( title, '' ) || ' ' || coalesce( album, '' ) )
            || to_tsvector( 'simple',  coalesce( artist, '' ) || ' ' || coalesce( title, '' ) || ' ' || coalesce( album, '' ) )
            @@ in_query;

    RETURN;

$$ LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION fn_get_tsquery_from_TEXT( in_query TEXT )
    RETURNS SETOF TSQUERY
    AS $$
BEGIN
    RETURN QUERY
        SELECT song
          FROM song
         WHERE TO_TSVECTOR( 'english', COALESCE( artist, '' ) ) || TO_TSVECTOR( 'simple', COALESCE( artist, '' ) )
            || TO_TSVECTOR( 'english', COALESCE( title,  '' ) ) || TO_TSVECTOR( 'simple', COALESCE( title,  '' ) )
            || TO_TSVECTOR( 'english', COALESCE( album,  '' ) ) || TO_TSVECTOR( 'simple', COALESCE( album,  '' ) )
            @@ in_query;

    RETURN;
