checking existence of a table before updating its SERIAL

Поиск
Список
Период
Сортировка
От Matthias Apitz
Тема checking existence of a table before updating its SERIAL
Дата
Msg-id 20200608075358.GA17471@sh4-5.1blu.de
обсуждение исходный текст
Ответы Re: checking existence of a table before updating its SERIAL
Re: checking existence of a table before updating its SERIAL
Список pgsql-general
Hello,

We're updating the SERIAL of a bunch of tables with a SQL script which
does for any table:

/* table: idm_tasktab */
DO $$
DECLARE
  max_id int;
BEGIN
  SELECT INTO max_id GREATEST(COALESCE(max(taskid), 0),0) + 1 FROM idm_tasktab;
  RAISE NOTICE '% % %', 'idm_tasktab', 'taskid', max_id ;
  EXECUTE 'ALTER SEQUENCE idm_tasktab_taskid_seq RESTART ' || max_id::text;
END $$ LANGUAGE plpgsql;

Can some kind soul help me with doing a test for the existence of the
table to avoid the error message about non existing relation? 

Thanks in advance.

    matthias

-- 
Matthias Apitz, ✉ guru@unixarea.de, http://www.unixarea.de/ +49-176-38902045
Public GnuPG key: http://www.unixarea.de/key.pub



В списке pgsql-general по дате отправления:

Предыдущее
От: Laurenz Albe
Дата:
Сообщение: Re: Multitenent architecture
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: checking existence of a table before updating its SERIAL