Re: Setting sequence ids after importing data - Mailing list pgsql-novice

From Tom Lane
Subject Re: Setting sequence ids after importing data
Date
Msg-id 4006.1147144047@sss.pgh.pa.us
Whole thread Raw
In response to Re: Setting sequence ids after importing data  ("Hari Patel" <hariwise@gmail.com>)
List 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 by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: Setting sequence ids after importing data
Next
From: Sean Davis
Date:
Subject: No quoting in copy CSV mode