[SQL] How to Convert Integer to Serial

2010-10-28 Thread venkat
Dear All,

  I want to convert integer datatype to serial datatype.. is that
possible.Please let me know.

Thanks and Regards,

Ven


Re: [SQL] How to Convert Integer to Serial

2010-10-28 Thread venkat
Dear All,

  I got the solution... Here is my query

ALTER TABLE DemoTable  ALTER gid TYPE INT2;

Thanks again


On Fri, Oct 29, 2010 at 10:18 AM, venkat  wrote:

> Dear All,
>
>   I want to convert integer datatype to serial datatype.. is that
> possible.Please let me know.
>
> Thanks and Regards,
>
> Ven
>


Re: [SQL] How to Convert Integer to Serial

2010-10-28 Thread Shoaib Mir
On Fri, Oct 29, 2010 at 3:48 PM, venkat  wrote:

> Dear All,
>
>   I want to convert integer datatype to serial datatype.. is that
> possible.Please let me know.
>
>
I don't think ALTER TABLE will let you do that... so the best way to achieve
the same is:

- Create a sequence for the column (set the start of sequence according to
the values you got already in the column)
- Now set this sequence as the default value for that specific column which
you need to ALTER like this:

ALTER TABLE tablename ALTER COLUMN columnname
SET DEFAULT nextval('newsequence'::regclass);

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


Re: [SQL] How to Convert Integer to Serial

2010-10-28 Thread Shoaib Mir
On Fri, Oct 29, 2010 at 3:58 PM, venkat  wrote:

> Dear All,
>
>   I got the solution... Here is my query
>
> ALTER TABLE DemoTable  ALTER gid TYPE INT2;
>
>
>
Are you sure that you have converted here to a SERIAL type?

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


Re: [SQL] How to Convert Integer to Serial

2010-10-28 Thread venkat
ohhh,, sorry... It was wrong post..sorry again...

On Fri, Oct 29, 2010 at 10:30 AM, Shoaib Mir  wrote:

> On Fri, Oct 29, 2010 at 3:48 PM, venkat  wrote:
>
>> Dear All,
>>
>>   I want to convert integer datatype to serial datatype.. is that
>> possible.Please let me know.
>>
>>
> I don't think ALTER TABLE will let you do that... so the best way to
> achieve the same is:
>
> - Create a sequence for the column (set the start of sequence according to
> the values you got already in the column)
> - Now set this sequence as the default value for that specific column which
> you need to ALTER like this:
>
> ALTER TABLE tablename ALTER COLUMN columnname
> SET DEFAULT nextval('newsequence'::regclass);
>
> --
> Shoaib Mir
> http://shoaibmir.wordpress.com/
>