CREATE OR REPLACE FUNCTION food600.getidriadokmaster(
	midriadok integer,
	mtabulka character varying)
    RETURNS character varying
    LANGUAGE 'plpgsql'

    COST 100
    VOLATILE 
    
AS $BODY$
DECLARE idriadokmaster INTEGER;
BEGIN
IF mtabulka LIKE '%.%' THEN 
	EXECUTE format('SELECT idriadok_master FROM %s WHERE idriadok = %s', mtabulka, midriadok) INTO idriadokmaster;
ELSE
	EXECUTE format('SELECT idriadok_master FROM %s WHERE idriadok = %s', 'food600.'||mtabulka, midriadok) INTO idriadokmaster;
END IF;
RETURN btrim(idriadokmaster::character(20));
END
$BODY$;
