views:

272

answers:

2

My question is kind of simple.

Is it possible to use subqueries within alter expressions in PostgreSQL?

I want to alter a sequence value based on a primary key column value.

I tried using the following expression, but it wouldn't execute.

alter sequence public.sequenceX restart with (select max(table_id)+1 from table)

Thanks in advance

+7  A: 

I don't believe you can do it like that but you should be able to use the setval function direction which is what the alter does.

select setval('sequenceX', (select max(table_id)+1 from table), false)

The false will make it return the next sequence number as exactly what is given.

Arthur Thomas
Exactly what I was looking for!Thanks a lot!
Danmaxis
A: 

thanq very much

Siri