Import id column then convert to SEQUENCE?

Started by gvimover 15 years ago4 messagesgeneral
Jump to latest
#1gvim
gvimrc@gmail.com

I'm migrating a database from MySQL and need to keep the original `id` column (AUTO_INCREMENT) intact so my plan is to create an simple integer `id` column, import the data then convert the new `id` column to a SEQUENCE. Is this possible/the best solution? Maybe a migration utility would be better? Suggestions?

gvim

#2Shoaib Mir
shoaibmir@gmail.com
In reply to: gvim (#1)
Re: Import id column then convert to SEQUENCE?

On Fri, Dec 10, 2010 at 2:44 PM, gvim <gvimrc@gmail.com> wrote:

I'm migrating a database from MySQL and need to keep the original `id`
column (AUTO_INCREMENT) intact so my plan is to create an simple integer
`id` column, import the data then convert the new `id` column to a SEQUENCE.
Is this possible/the best solution? Maybe a migration utility would be
better? Suggestions?

Try using SERIAL datatype.

--
Shoaib Mir
http://shoaibmir.wordpress.com/

#3Shoaib Mir
shoaibmir@gmail.com
In reply to: Shoaib Mir (#2)
Re: Import id column then convert to SEQUENCE?

On Fri, Dec 10, 2010 at 2:53 PM, Shoaib Mir <shoaibmir@gmail.com> wrote:

On Fri, Dec 10, 2010 at 2:44 PM, gvim <gvimrc@gmail.com> wrote:

I'm migrating a database from MySQL and need to keep the original `id`
column (AUTO_INCREMENT) intact so my plan is to create an simple integer
`id` column, import the data then convert the new `id` column to a SEQUENCE.
Is this possible/the best solution? Maybe a migration utility would be
better? Suggestions?

Try using SERIAL datatype.

I guess I misread it... use the following:

- Import all the data into say an integer column.
- Now create a sequence and give it a start value of where your import
ended.
- Make the default value for the column using the new sequence.

--
Shoaib Mir
http://shoaibmir.wordpress.com/

#4Vick Khera
vivek@khera.org
In reply to: Shoaib Mir (#3)
Re: Import id column then convert to SEQUENCE?

On Thu, Dec 9, 2010 at 10:56 PM, Shoaib Mir <shoaibmir@gmail.com> wrote:

I guess I misread it... use the following:

- Import all the data into say an integer column.
- Now create a sequence and give it a start value of where your import
ended.
- Make the default value for the column using the new sequence.

create the table with a SERIAL column, which will make the sequence
and set the auto increment default as you wanted.

import the data

update the sequence with setval() to the next highest value you want
it to return, usually max()+1 of the populated column.