Re: Question about setval() function - Mailing list pgsql-general

From Scott Marlowe
Subject Re: Question about setval() function
Date
Msg-id Pine.LNX.4.33.0205140926330.2855-100000@css120.ihs.com
Whole thread Raw
In response to Question about setval() function  (Erwin Ambrosch <ambre@ebutec.com>)
List 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).


pgsql-general by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Configure problems with readline Mandrake 8.2 and
Next
From: Martín Marqués
Date:
Subject: Re: restoreing dumps fail