“crear funciones postgresql” Código de respuesta

Crear función en PostgreSQL

create [or replace] function function_name(param_list)
   returns return_type 
   language plpgsql
as $$
declare 
-- variable declaration
begin
 -- logic
end;
$$
Powerful Pheasant

función postgreSQL

Create or replace Function public.my_function(p_el1 int, p_el2 int, p_name char)
Returns table (id int, price int)
language plpgsql

as
$$
	declare
		v_total int;
	
	begin
		-- insert into first table
		insert into my_table1
			(added_name)
		values
			(p_name);

		-- Insert the result of a calculation in a variable
		select (p_el1 + p_el2) into v_total;
	
		-- Update a second table
		update my_table2 mt
		set
			price = v_total
		where
			mt.name = p_name;
		
		-- Return the result of a query
		return query (select
							mt.id,
							mt.price
						from
							my_table2 mt
						where
							mt.name = p_name);
		
	end;
$$

Puzzled Penguin

crear funciones postgresql

CREATE OR REPLACE FUNCTION auditlogfunc() RETURNS TRIGGER AS $example_table$
   BEGIN
      INSERT INTO AUDIT(EMP_ID, ENTRY_DATE) VALUES (new.ID, current_timestamp);
      RETURN NEW;
   END;
$example_table$ LANGUAGE plpgsql;
Good Gharial

Respuestas similares a “crear funciones postgresql”

Preguntas similares a “crear funciones postgresql”

Más respuestas relacionadas con “crear funciones postgresql” en Sql

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código