## 1.88. slon_quote_input( text )

Function Properties
Language: PLPGSQL
Return Type: text

quote all words that aren[apos ]t quoted yet

    declare
        p_tab_fqname alias for $1;
        v_temp_fqname text default '';
        v_pre_quoted text[] default '{}';
        v_pre_quote_counter smallint default 0;
        v_count_fqname smallint default 0;
        v_fqname_split text[];
        v_quoted_fqname text default '';
    begin
        v_temp_fqname := p_tab_fqname;

        LOOP
    	v_pre_quote_counter := v_pre_quote_counter + 1;
    	v_pre_quoted[v_pre_quote_counter] :=
    	    substring(v_temp_fqname from '%#""%"#"%' for '#');
    	IF v_pre_quoted[v_pre_quote_counter] <> '' THEN
    	    v_temp_fqname := replace(v_temp_fqname,
    	        v_pre_quoted[v_pre_quote_counter], '@' ||
    		v_pre_quote_counter);
    	ELSE
    	    EXIT;
    	END IF;
        END LOOP;

        v_fqname_split := string_to_array(v_temp_fqname , '.');
        v_count_fqname := array_upper (v_fqname_split, 1);

        FOR i in 1..v_count_fqname LOOP
            IF substring(v_fqname_split[i],1,1) = '@' THEN
                v_quoted_fqname := v_quoted_fqname ||
    		v_pre_quoted[substring (v_fqname_split[i] from 2)::int];
            ELSE
                v_quoted_fqname := v_quoted_fqname || '"' ||
    		v_fqname_split[i] || '"';
            END IF;

            IF i < v_count_fqname THEN
                v_quoted_fqname := v_quoted_fqname || '.' ;
            END IF;
        END LOOP;

        return v_quoted_fqname;
    end;