Search
 
SCRIPT & CODE EXAMPLE
 

SQL

create function in postgresql

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

postgresql function

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;
$$

Comment

function in postgresql

CREATE OR REPLACE FUNCTION totalRecords ()
RETURNS integer AS $total$
declare
	total integer;
BEGIN
   SELECT count(*) into total FROM COMPANY;
   RETURN total;
END;
$total$ LANGUAGE plpgsql;
Comment

create function 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;
Comment

PREVIOUS NEXT
Code Example
Sql :: FirebaseException ([cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.) 
Sql :: epoch time converter in snowflake 
Sql :: postgresql allow remote connection 
Sql :: get row affected mysql 
Sql :: alter database name script 
Sql :: job for postgresql.service failed because the control process exited with error code. see "systemctl status postgresql.service" and "journalctl -xe" for details. 
Sql :: view t-sql mail configuration 
Sql :: sql select where in list 
Sql :: how select a json value in mysql 
Sql :: postgresql get last 10 records 
Sql :: how to create new user and database postgresql in ubuntu 
Sql :: trim leading zeros in sql 
Sql :: trigger in postgresql to change incoming entry 
Sql :: convert rows to string sql server 
Sql :: delete record mysql query 
Sql :: SQL rounding numbers 
Sql :: psql change table schema 
Sql :: delete dublicate rows sql 
Sql :: oracle auto increment primary key 
Sql :: show slave status mysql 
Sql :: sqlite to csv statement 
Sql :: running percentage of total postgres 
Sql :: sql merge 
Sql :: identify number of rows in sql 
Sql :: drop index in sql 
Sql :: sql query to list all tables in a database sql server 
Sql :: current date sql 
Sql :: restart sql server command line linux 
Sql :: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client vs code 
Sql :: mysql store ip address 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =