pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
alter sequence + subqueries
3+ messages / 3 participants
[nested] [flat]

* alter sequence + subqueries
@ 2005-09-16 22:36  jeff sacksteder <jsacksteder@gmail.com>
  0 siblings, 2 replies; 3+ messages in thread

From: jeff sacksteder @ 2005-09-16 22:36 UTC (permalink / raw)
  To: pgsql-sql

The postgres-specific sql extension 'ALTER SEQUENCE' does not appear to 
support subqueries.

I have inserted some data into a table, including values in the primary key. 
I want to reset the associated sequence so that any further records to be 
inserted into that table resume numbering correctly. The statement I 
attempted was:

ALTER SEQUENCE foo_id_seq 
RESTART WITH (SELECT max(id) FROM foo);

Is this syntax correct and supported?

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: alter sequence + subqueries
@ 2005-09-16 23:19  Alvaro Herrera <alvherre@alvh.no-ip.org>
  parent: jeff sacksteder <jsacksteder@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Alvaro Herrera @ 2005-09-16 23:19 UTC (permalink / raw)
  To: jeff sacksteder <jsacksteder@gmail.com>; +Cc: pgsql-sql

On Fri, Sep 16, 2005 at 06:36:48PM -0400, jeff sacksteder wrote:
> The postgres-specific sql extension 'ALTER SEQUENCE' does not appear to 
> support subqueries.
> 
> I have inserted some data into a table, including values in the primary key. 
> I want to reset the associated sequence so that any further records to be 
> inserted into that table resume numbering correctly. The statement I 
> attempted was:
> 
> ALTER SEQUENCE foo_id_seq 
> RESTART WITH (SELECT max(id) FROM foo);
> 
> Is this syntax correct and supported?

No, but you could call the setval() function instead ...

-- 
Alvaro Herrera -- Valdivia, Chile         Architect, www.EnterpriseDB.com
Officer Krupke, what are we to do?
Gee, officer Krupke, Krup you! (West Side Story, "Gee, Officer Krupke")



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: alter sequence + subqueries
@ 2005-09-16 23:27  Michael Fuhr <mike@fuhr.org>
  parent: jeff sacksteder <jsacksteder@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Michael Fuhr @ 2005-09-16 23:27 UTC (permalink / raw)
  To: jeff sacksteder <jsacksteder@gmail.com>; +Cc: pgsql-sql

On Fri, Sep 16, 2005 at 06:36:48PM -0400, jeff sacksteder wrote:
> ALTER SEQUENCE foo_id_seq 
> RESTART WITH (SELECT max(id) FROM foo);
> 
> Is this syntax correct and supported?

Not according to the documentation; for an alternative see the
example under "User Comments":

http://www.postgresql.org/docs/8.0/interactive/sql-altersequence.html

-- 
Michael Fuhr



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-09-16 23:27 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-09-16 22:36 alter sequence + subqueries jeff sacksteder <jsacksteder@gmail.com>
2005-09-16 23:19 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2005-09-16 23:27 ` Michael Fuhr <mike@fuhr.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox