plpgsql code doen't work - Mailing list pgsql-general

From janek12@web.de
Subject plpgsql code doen't work
Date
Msg-id trinity-5c7cade3-67b5-4523-9c08-be7df04103f5-1378801246012@3capp-webde-bs42
Whole thread Raw
Responses Re: plpgsql code doen't work
List pgsql-general
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


pgsql-general by date:

Previous
From: roppert
Date:
Subject: Re: [pgeu-general] Call for design: PostgreSQL mugs
Next
From: Emre ÖZTÜRK
Date:
Subject: FW: Single Line Query Logging