Skip site navigation (1) Skip section navigation (2)

Re: Setting sequence ids after importing data

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
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 02:20:07
Message-ID: 4BF1F818-DD83-4F0E-9BFC-2152613566C9@seespotcode.net (view raw or flat)
Thread:
Lists: pgsql-novice
On May 9, 2006, at 10:59 , Hari Patel wrote:

> 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:                          ^

Try just
setval('foo_id_seq',10)
or
PEFORM setval('foo_id_seq', 10)

It's just a function call, and since you're not saving the return  
value, you don't use SELECT. SELECT has different syntax in PL/pgSQL  
than in SQL.

Hope this helps.

Michael Glaesemann
grzm seespotcode net




In response to

pgsql-novice by date

Next:From: Tom LaneDate: 2006-05-09 03:07:27
Subject: Re: Setting sequence ids after importing data
Previous:From: Hari PatelDate: 2006-05-09 01:59:07
Subject: Re: Setting sequence ids after importing data

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group