* Пример на диалекте SQL CREATE OR REPLACE FUNCTION client.fx_admin_row(integer) RETURNS client.admins AS $BODY$ -- -- Получение строки admin -- SELECT * FROM client.admins WHERE admin_id=$1; -- $BODY$ LANGUAGE 'sql' VOLATILE SECURITY DEFINER COST 100; ALTER FUNCTION client.fx_admin_row(integer) OWNER TO sk4_admin; GRANT EXECUTE ON FUNCTION client.fx_admin_row(integer) TO sk4_admin; GRANT EXECUTE ON FUNCTION client.fx_admin_row(integer) TO public; * Пример на диалекте plpgsql CREATE OR REPLACE FUNCTION client.fx_user_row(id integer) RETURNS client.users AS $BODY$ -- -- Получение строки user -- DECLARE r client.users%rowtype; BEGIN IF NOT EXISTS(SELECT * FROM client.users WHERE user_id=$1) THEN RAISE EXCEPTION 'User "%" not found!', $1; END IF; SELECT * INTO r FROM client.users WHERE user_id=$1; RETURN r; END -- $BODY$ LANGUAGE 'plpgsql' VOLATILE SECURITY DEFINER COST 100; ALTER FUNCTION client.fx_user_row(integer) OWNER TO sk4_admin; GRANT EXECUTE ON FUNCTION client.fx_user_row(integer) TO sk4_admin; GRANT EXECUTE ON FUNCTION client.fx_user_row(integer) TO public;
SQL Справочник v0.05 © 2007-2025 Igor Salnikov aka SunDoctor