Re: Setting sequence ids after importing data

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Setting sequence ids after importing data
Дата
Msg-id 4006.1147144047@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Setting sequence ids after importing data  ("Hari Patel" <hariwise@gmail.com>)
Список pgsql-novice
"Hari Patel" <hariwise@gmail.com> writes:
> CREATE function set_sequence_ids() RETURNS INTEGER AS '
> DECLARE
>   arg INTEGER;
> BEGIN
>   select into arg max(id) from foo;
>   select setval('foo_id_seq', 10);
>   return arg;
> END;
> ' LANGUAGE 'plpgsql';

> I get the following error in psql.

> psql:func.sql:9: ERROR:  syntax error at or near "foo_id_seq" at charact
> er 152
> psql:func.sql:9: LINE 6:   select setval('foo_id_seq', 10);
> psql:func.sql:9:                          ^

You've got a quoting problem: either double the quotes embedded in the
function body, or use dollar quotes ($$) to surround the function body
instead of plain quotes (').

BTW, seems like the above is wrong anyway: don't you want to set the
sequence to arg+1, rather than constant 10?

            regards, tom lane

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

Предыдущее
От: Michael Glaesemann
Дата:
Сообщение: Re: Setting sequence ids after importing data
Следующее
От: Sean Davis
Дата:
Сообщение: No quoting in copy CSV mode