Search
 
SCRIPT & CODE EXAMPLE
 

SQL

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

postgresql functions

CASE
     WHEN condition_1  THEN result_1
     WHEN condition_2  THEN result_2
     ...
     ELSE  result_n
END
Comment

PREVIOUS NEXT
Code Example
Sql :: sql year 
Sql :: left join 
Sql :: sql query to linq converter online 
Sql :: union all in sql 
Sql :: postgresql gset 
Sql :: missing index for constraint error in mysql 
Sql :: on delete set default 
Sql :: sql joins in python 
Sql :: query to generate query to drop primary keys or foreign key in ms sql server 
Sql :: ajax error exception handeling 
Sql :: ring execute query then print the query result. 
Sql :: mysql coonect sample code 
Sql :: sysdatetimeoffset 
Sql :: sql countif 
Sql :: sort by 
Sql :: where field is null sql knex 
Sql :: compare subqueries oracle 
Sql :: Test SQL snippets 
Sql :: get who is hired in specific month in sql 
Sql :: select multiple columns count one column and group by one column in one table 
Sql :: Character Limitation in sp_executesql sql server 
Sql :: how to set sql_mode for a query in CI model 
Sql :: price-colour 
Sql :: oracle procedure chain step 
Sql :: remove an object that is dependent on a column in sql 
Sql :: heavy table in mysql 
Sql :: procedure excute monthly oracle 
Sql :: Creating a comment and reply system PHP and MySQL 
Sql :: druid sql list all tables 
Sql :: case sensitive sql 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =