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

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: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
"Hari Patel" <hariwise(at)gmail(dot)com> writes:
> CREATE function set_sequence_ids() RETURNS INTEGER AS '
>   arg INTEGER;
>   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

pgsql-novice by date

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

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