Как узнать дату модификации ИП?

Можно ли узнать дату модификации и / или создания SP в PostgreSQL 9.4?

Мне нужно идентифицировать их, чтобы загрузить их при следующем развертывании.


person Max    schedule 22.11.2017    source источник
comment
SP - это функция, определяемая пользователем? ..   -  person Vao Tsun    schedule 22.11.2017
comment
stackoverflow.com/questions/2577168/   -  person Vao Tsun    schedule 22.11.2017
comment
@VaoTsun - 2577168 устарело - теперь PostgreSQL имеет триггеры событий, и эта проблема может быть решена с помощью системных функций.   -  person Pavel Stehule    schedule 22.11.2017
comment
@PavelStehule да, полностью согласен, кстати - почему никто не добавляет это исправление в 2577168? Я думаю, что отсутствие last_ddl в postgres было священной войной перед триггерами событий   -  person Vao Tsun    schedule 22.11.2017
comment
@VaoTsun - частично верно, это было возможно с некоторыми расширениями C, но не было простого простого решения. Философия PostgreSQL: ничего не делай, если не можешь делать правильно. Имеет достоинства и недостатки.   -  person Pavel Stehule    schedule 22.11.2017
comment
Всем спасибо за ответы !!!   -  person Max    schedule 23.11.2017


Ответы (1)


PostgreSQL не имеет этой функции. Вы можете создать собственную таблицу и обновить ее с помощью триггеров событий.

create table updates(proc regprocedure primary key, t timestamp);

create or replace function event_trigger_for_ddl_command_end()
returns event_trigger as $$
declare obj record;
begin
  for obj in select * from pg_event_trigger_ddl_commands()
  loop
    if obj.classid = 'pg_proc'::regclass then
      insert into updates values(obj.objid, current_timestamp)
          on conflict (proc) do update set t = current_timestamp
                             where updates.proc = excluded.proc;
    end if;
  end loop;
end;
$$ language plpgsql;

create event trigger trigger_for_ddl_command_end
  on ddl_command_end
  execute procedure event_trigger_for_ddl_command_end();

create or replace function fx(a int) returns int as $$ select 1 $$ language sql;

postgres=# select * from updates ;
+-------------+----------------------------+
|    proc     |             t              |
+-------------+----------------------------+
| fx(integer) | 2017-11-22 14:21:11.367036 |
+-------------+----------------------------+
(1 row)

-- alternative code without INSERT ON CONFLICT
create or replace function event_trigger_for_ddl_command_end()
returns event_trigger as $$
declare obj record;
begin
  for obj in select * from pg_event_trigger_ddl_commands()
  loop
    if obj.classid = 'pg_proc'::regclass then
      begin
        update updates set t = current_timestamp
           where proc = obj.objid;
        if not found then
          begin
            insert into updates values(obj.objid, current_timestamp);
          exception when unique_violation then
            update updates set t = current_timestamp
               where proc = obj.objid;
          end;
        end if;
    end if;
  end loop;
end;
$$ language plpgsql;
person Pavel Stehule    schedule 22.11.2017
comment
При создании SP event_trigger_for_ddl_command_end () я получаю следующее: ERROR: error de sintaxis en o cerca de «on» СТРОКА 8: при конфликте (proc) do update set t = current_times ... - person Max; 24.11.2017
comment
@Max Какая у вас версия postgres? - person Pavel Stehule; 24.11.2017
comment
У меня PostgreSQL 9.4 - person Max; 25.11.2017
comment
@ Макс хмм 9.4. не поддерживает INSERT ON CONFLICT. - person Pavel Stehule; 25.11.2017