Tutorial by Examples

A simple PL/pgSQL function: CREATE FUNCTION active_subscribers() RETURNS bigint AS $$ DECLARE -- variable for the following BEGIN ... END block subscribers integer; BEGIN -- SELECT must always be used with INTO SELECT COUNT(user_id) INTO subscribers FROM users WHERE subscribed...
CREATE [OR REPLACE] FUNCTION functionName (someParameter 'parameterType') RETURNS 'DATATYPE' AS $_block_name_$ DECLARE --declare something BEGIN --do something --return something END; $_block_name_$ LANGUAGE plpgsql;
Options for returning in a PL/pgSQL function: Datatype List of all datatypes Table(column_name column_type, ...) Setof 'Datatype' or 'table_column'
creating custom exception 'P2222': create or replace function s164() returns void as $$ begin raise exception using message = 'S 164', detail = 'D 164', hint = 'H 164', errcode = 'P2222'; end; $$ language plpgsql ; creating custom exception not assigning errm: create or replace function s...

Page 1 of 1