Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General »

Problema a la hora de acrear una funcion en Postgresql

Estas en el tema de Problema a la hora de acrear una funcion en Postgresql en el foro de Bases de Datos General en Foros del Web. Buenas a todos, tengo la siguiente funcion Código: alter function tarjetero.insertarEmpresa( char varying, integer, integer, char varying, char varying, char varying, char varying, bytea) RETURNS ...
  #1 (permalink)  
Antiguo 28/10/2016, 08:14
 
Fecha de Ingreso: febrero-2014
Mensajes: 60
Antigüedad: 10 años, 1 mes
Puntos: 0
Problema a la hora de acrear una funcion en Postgresql

Buenas a todos, tengo la siguiente funcion

Código:
alter function tarjetero.insertarEmpresa(
 char varying, 
 integer, 
 integer, 
 char varying, 
 char varying, 
 char varying, 
 char varying, 
 bytea)
RETURNS TEXT AS 
$res$
declare 
	id integer;
begin	

IF EXISTS (SELECT id_empresa
	FROM tarjetero.empresa
	WHERE int_disponible = 0
	LIMIT 1)
	
	then	
	
	SELECT id = id_empresa
	FROM tarjetero.empresa
	WHERE int_disponible = 0
	LIMIT 1;

	UPDATE tarjetero.empresa
	   SET
	   str_nombre=$1, 
	   int_tlf1=$2, 
	   int_tlf2=$3, 
	   str_direccion1=$4, 
	   str_direccion2=$5, 
	   str_direccion3=$6, 
	   str_email=$7, 
	   int_disponible=1, 
	   bytea_img=$8
	 WHERE id_empresa = id;


	return 'Modificado';
ELSE
	INSERT INTO tarjetero.empresa(
            id_empresa, str_nombre, int_tlf1, int_tlf2, str_direccion1, str_direccion2, 
            str_direccion3, str_email, int_disponible, bytea_img)
    VALUES (DEFAULT, $1, $2, $3, $4, $5, 
            $6, $7, 1, $8);

	return 'insertado';
end if;
END
$res$ LANGUAGE plpgsql;

Pero me da el siguiente error:

ERROR: error de sintaxis en o cerca de «TEXT»
LÍNEA 10: RETURNS TEXT AS
^
********** Error **********

ERROR: error de sintaxis en o cerca de «TEXT»
SQL state: 42601
Character: 161


Alguien sabe en que estoy fallando? Por mucho que miro, no le veo el fallo :S
  #2 (permalink)  
Antiguo 28/10/2016, 08:47
Avatar de Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 8 meses
Puntos: 774
Respuesta: Problema a la hora de acrear una funcion en Postgresql

Y los nombres de variables en la declaracion de los parametros de entrada??


Código SQL:
Ver original
  1. ALTER FUNCTION tarjetero.insertarEmpresa(
  2.  var1 CHAR VARYING,
  3.  var2 INTEGER,
  4.  var3 INTEGER,
  5.  var4 CHAR VARYING,
  6.  var5 CHAR VARYING,
  7.  var6 CHAR VARYING,
  8.  var7 CHAR VARYING,
  9.  var8 bytea)

Sintaxis del create or replace function

CREATE [ OR REPLACE ] FUNCTION
name ( [ [ argmode ] [ argname ] argtype [ { DEFAULT | = } default_expr ] [, ...] ] )
[ RETURNS rettype
| RETURNS TABLE ( column_name column_type [, ...] ) ]
{ LANGUAGE lang_name
| WINDOW
| IMMUTABLE | STABLE | VOLATILE
| CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
| [ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER
| COST execution_cost
| ROWS result_rows
| SET configuration_parameter { TO value | = value | FROM CURRENT }
| AS 'definition'
| AS 'obj_file', 'link_symbol'
} ...
[ WITH ( attribute [, ...] ) ]

https://www.postgresql.org/docs/9.1/...efunction.html
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me

Etiquetas: funcion, postgresql, sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:58.