Re: Setting sequence ids after importing data

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Hari Patel" <hariwise(at)gmail(dot)com>
Cc: "Sean Davis" <sdavis2(at)mail(dot)nih(dot)gov>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Setting sequence ids after importing data
Date: 2006-05-09 03:07:27
Message-ID: 4006.1147144047@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

"Hari Patel" <hariwise(at)gmail(dot)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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message João Miguel Ferreira 2006-05-09 09:44:13 Re: database size grows (even after vacuum (full and analyze))....
Previous Message Michael Glaesemann 2006-05-09 02:20:07 Re: Setting sequence ids after importing data