Professional Documents
Culture Documents
1.- Create a new database ‘exercises’ with a schema ‘p08’ (all owned by user alumne)
and import instr2.sql and EMPLOYEESDB.sql inside that schema. Set the appropiate
permissions.
Create database exercises;
\c exercises
create schema p08;
\li C:/Users/Ignacio/Desktop/DataBase/instr2.sql
\li C:/Users/Ignacio/Desktop/DataBase/EMPLOYEESDB.sql
2.- Connect to the database as ‘alumne’ and to the rest of exercise using this
connection.
pgcli -h 192.168.62.25 -p 5432 -U alumne exercises
Alter database exercises owner to alumne;
alter schema p08 owner to alumne;
3.- Run the following query (first read the source code of the function):
select INSTR2(E.surname, 'A') from EMPLOYEES E;
4.- Create a function ‘myadd’ that receives two integers and returns the result of their
addition.
create or replace function myadd(var1 integer,var2 integer) returns integer as $$
begin
return var1+var2;
end;
$$ language plpgsql;
5.- Create a function ‘add_one’ that receives an integer and returns that number
incremented by one.
create or replace function myrtrim(var1 text, var2 text, var3 text) returns text as $$
begin
return concat($1,rtrim($2),$3);
end;
$$ language plpgsql;
create or replace function myltrim(var1 text, var2 text, var3 text) returns text as $$
begin
return concat($1,ltrim($2),$3);
end;
$$ language plpgsql;
8.- Implement the function CONCAT2 using the operator ||. Remember that this
function can accept a variable number of arguments. It’s mandatory to use FOREACH.
Clues:
● http://www.postgresqltutorial.com/plpgsql-function-parameters/
● https://www.postgresql.org/docs/current/plpgsql-control-structures.html
9.- Write a function ‘mysign’ to check whether a number is positive, negative or zero.
13.- Write a factorial function. Make a recursive version and an iterative version.
En SQL Shell
\c exercises
\df p08.
16.- Delete all the functions you created in this list.
drop function p08.filteremployee(inout integer, out text, out text, out integer);