Загрузка данных


-- DROP FUNCTION mail.api_new_message_group_byte_file(text, text, int4, _bytea, _text, text, int4);

CREATE OR REPLACE FUNCTION mail.api_new_message_group_byte_file(curtitul text, curbody text, group_addr integer, context_array bytea[] DEFAULT NULL::bytea[], namefiles text[] DEFAULT NULL::text[], datesend text DEFAULT NULL::text, curmailbox integer DEFAULT 1)
RETURNS text
LANGUAGE plpgsql
AS $function$
declare
    attr     text[];
    listfiles text[];
    listid    int[];
    result    text;
    dformat text := 'DD.MM.YYYY HH24:MI:SS';
    tempdt    timestamp := null;
begin
    select array_agg(mail) into attr from mail.members_group_recipients where id_group=group_addr;
    raise notice ' add - %', attr;
    if datesend is not null then
        begin
         tempdt := to_timestamp(datesend,dformat);
        exception
            when others then
                tempdt := null;
        end;
    end if;
    raise notice ' dt - %', tempdt;

    insert into mail.list_mails
    (message, list_recipient, title, list_attachment_bin, list_filename_bin, date_send, sendmailbox)
    values (curbody, attr, curtitul, context_array, namefiles, tempdt, curmailbox );
    return 'Ok';
end;
$function$
;