[Pgsql-ayuda] Funcion isnumeric???
Gunnar Wolf
gwolf@gwolf.cx
Wed, 29 Oct 2003 12:45:01 -0600
Carmen Gloria Sepulveda Dedes dijo [Tue, Oct 28, 2003 at 12:55:37PM -0300]:
> Hola a todos
>
> Necesito una funcion que implemente algo asi como
> is_number(varchar) ... que retorne 1 si el varchar que
> recibe es un valor que es un numero o que retorne 0 si
> es lo contrario.
>
> Busque algo asi en postgres, pero no lo encontre.
>
> Alguien sabe como puedo hacerlo? o sabe si la funcion
> efectivamente existe?
Ummm... Sin la menor experiencia al respecto, me suena algo así:
Cuando tú defines una función en plpgsql, le indicas los tipos de
datos de sus argumentos, y la defines en función de ellos. Por tanto,
podrías crear un juego de funciones muy simples así:
CREATE OR REPLACE FUNCTION is_numeric(integer) RETURNS bool AS
'BEGIN
RETURN ''t'';
END;' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION is_numeric(numeric) RETURNS bool AS
'BEGIN
RETURN ''t'';
END;' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION is_numeric(varchar) RETURNS bool AS
'BEGIN
RETURN ''f'';
END;' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION is_numeric(text) RETURNS bool AS
'BEGIN
RETURN ''f'';
END;' LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION is_numeric(bool) RETURNS bool AS
'BEGIN
RETURN ''f'';
END;' LANGUAGE 'plpgsql';
etc.
Poco elegante, pero sencillo :)
Saludos,
--
Gunnar Wolf - gwolf@gwolf.cx - (+52-55)5630-9700 ext. 1366
PGP key 1024D/8BB527AF 2001-10-23
Fingerprint: 0C79 D2D1 2C4E 9CE4 5973 F800 D80E F35A 8BB5 27AF