Re: Question about setval() function

From: Scott Marlowe <scott(dot)marlowe(at)ihs(dot)com>
To: Erwin Ambrosch <ambre(at)ebutec(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Question about setval() function
Date: 2002-05-14 15:27:16
Message-ID: Pine.LNX.4.33.0205140926330.2855-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 14 May 2002, Erwin Ambrosch wrote:

> Hi,
>
> the following doesn't work.
>
> SELECT setval('int_article_id_seq', SELECT max(id) FROM int_article);
>
> I also tried to cast in the second argument, but with no success.
>
> SELECT setval('int_article_id_seq', SELECT CAST(max(id) FROM int_article AS
> INT4));

You're doing it (just a little bit) wrong. sub selects should ALWAYS be
enclosed by () pairs, so...

SELECT setval('int_article_id_seq', (SELECT CAST(max(id) FROM int_article
AS INT4)));

should work (it does on my system).

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2002-05-14 15:27:34 Re: restoreing dumps fail
Previous Message Tom Lane 2002-05-14 15:23:40 Re: Question about setval() function