CREATE OR REPLACE FUNCTION food600.getidriadokslave(
	midriadokmaster integer,
	mtabulka character varying)
    RETURNS character varying
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE 
AS $BODY$
DECLARE midriadok INTEGER;
BEGIN
IF mtabulka LIKE '%.%' THEN 
	EXECUTE format('SELECT idriadok FROM %s WHERE idriadok_master = %s', mtabulka, midriadokmaster) INTO midriadok;	
ELSE
	EXECUTE format('SELECT idriadok FROM %s WHERE idriadok_master = %s', 'food600.'||mtabulka, midriadokmaster) INTO midriadok;
END IF;
RETURN btrim(midriadok::character(20));
END
$BODY$;
