Search Postgresql Archives

plpgsql code doen't work

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, 
 
I found following code:

create or replace function plpgsql_edit_distance(stra text, strb text)
	returns integer as $$
declare
    rows integer;
    cols integer;
begin
    rows := length(stra);
    cols := length(strb);

    IF rows = 0 THEN
    	return cols;
    END IF;
    IF cols = 0 THEN
	return rows;
    END IF;

    declare
	row_u integer[];
	row_l integer[];
	diagonal integer;
	upper integer;
	left integer;
    begin
	FOR i in 0..cols LOOP
	    row_u[i] := i;
	END LOOP;

	FOR i IN 1..rows LOOP
	    row_l[0] := i;
	    FOR j IN 1..cols LOOP
	        IF substring (stra, i, 1) = substring (strb, j, 1) THEN
		    diagonal := row_u[j-1];
		else
		    diagonal := row_u[j-1] + 1;
		END IF;
		upper := row_u[j] + 1;
		left := row_l[j-1] + 1;
		row_l[j] := int4smaller(int4smaller(diagonal, upper), left);
		END LOOP;
            row_u := row_l;
	END LOOP;
	return row_l[cols];
    end;
end
$$ language 'plpgsql' immutable strict;

Does anyone know why the colums :"row_l[j] := int4smaller(int4smaller(diagonal, upper), left);" doesn't work.
 
Janek Sendrowski


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux