sqlines
sqlines copied to clipboard
informix to postgres: VARCHAR(100) function return removed
This informix function:
CREATE FUNCTION cf_cde_ParseRight( avc_ref VARCHAR(100) )
RETURNS VARCHAR(100) WITH (NOT VARIANT);
DEFINE li_pos INTEGER;
DEFINE lvc_return VARCHAR(100);
LET lvc_return = UPPER(TRIM(avc_ref));
IF NVL( lvc_return, '' ) != '' THEN
LET li_pos = crs_InStr(1, lvc_return, ' & ');
IF li_pos > 1 THEN
LET lvc_return = SUBSTRING(lvc_return FROM li_pos + 3) ;
END IF
END IF;
RETURN TRIM(lvc_return);
END FUNCTION;
Gets converted to this PostgreSQL function:
CREATE OR REPLACE FUNCTION cf_cde_ParseRight( avc_ref VARCHAR(100) )
RETURNS AS $$
VARCHAR(100) WITH (NOT VARIANT);
DECLARE li_pos INTEGER;
lvc_return VARCHAR(100);
BEGIN
lvc_return := UPPER(TRIM(avc_ref));
IF COALESCE( lvc_return, '' ) != '' THEN
li_pos := crs_InStr(1, lvc_return, ' & ');
IF li_pos > 1 THEN
lvc_return := SUBSTRING(lvc_return FROM li_pos + 3) ;
END IF;
END IF;
RETURN TRIM(lvc_return);
END;
$$ LANGUAGE plpgsql;
See the missing return type in RETURNS AS $$
also note as the VARCHAR return was moved below the RETURNS line, before the WITH (NOT VARIANT) statement which is also bogus (see #21)
The problem only occurs with RETURNS. Changing the statement to RETURNING fixes it.
#26 fixes this case by using the existing ParseInformixReturns for both RETURNS and RETURNING