CREATE OR REPLACE FUNCTION nn_db.user_get(
	in_search_value nn_db.user.username%TYPE)
RETURNS TABLE(
	pk_user nn_db.user.pk_user%TYPE
	, lastname nn_db.user.lastname%TYPE
	, firstname nn_db.user.firstname%TYPE
	, middlename nn_db.user.middlename%TYPE
	, username nn_db.user.username%TYPE
	, password_hash nn_db.user.password_hash%TYPE
	, email nn_db.user.email%TYPE
	, phone nn_db.user.phone%TYPE
	, is_admin nn_db.user.is_admin%TYPE
	, is_active nn_db.user.is_active%TYPE)
AS $$
BEGIN
	RETURN QUERY SELECT 
		nn_db.user.pk_user
		, nn_db.user.lastname
		, nn_db.user.firstname
		, nn_db.user.middlename
		, nn_db.user.username
		, nn_db.user.password_hash
		, nn_db.user.email
		, nn_db.user.phone
		, nn_db.user.is_admin
		, nn_db.user.is_active
	FROM nn_db.user
	WHERE
		nn_db.user.username ILIKE in_search_value
		OR nn_db.user.email ILIKE in_search_value;
END;
$$ LANGUAGE plpgsql