Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/05/2011, 07:31
nessemar
 
Fecha de Ingreso: noviembre-2010
Mensajes: 30
Antigüedad: 13 años, 5 meses
Puntos: 0
Respuesta: PostGis // Función que devuelve un booleano

Al final lo he solucionad utilizando un select into, y comprobando que el valor asignado a la variable coincida con el pasado como parámetro.

Código:
CREATE OR REPLACE FUNCTION devuelve_booleano(text, text)
  RETURNS boolean AS
$BODY$
/*comprieba que la primera posición de la cadena $1 sea $2*/
DECLARE
	car text;
BEGIN
	select into car substring($1, 1, 1);
	IF car=$2 THEN
		RETURN true;
	ELSE
		RETURN false;
	END IF;
END;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE STRICT
  COST 100;
ALTER FUNCTION devuelve_booleano(text, text) OWNER TO postgres;
Ahora el problema lo tengo con la siguiente función:

Código:
CREATE OR REPLACE FUNCTION str(text)
  RETURNS text AS
$BODY$
/*Devuelve */
DECLARE
	car text;
BEGIN
	select into car txt from  $1;
	return car;
END;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE STRICT
  COST 100;
ALTER FUNCTION str(text) OWNER TO postgres;
Pues al intentar compilarla salta un error de sintaxis que no alcanzo a entender...

Cita:
Iniciado por Pgadmin
ERROR: error de sintaxis en o cerca de «$1»
LINE 1: select txt from $1
^
QUERY: select txt from $1
CONTEXT: SQL statement in PL/PgSQL function "str" near line 7
¿me puede alguien orientar?