[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-sql
Subject:    Re: [SQL] How to Convert Integer to Serial
From:       venkat <ven.tammineni () gmail ! com>
Date:       2010-10-29 5:14:10
Message-ID: AANLkTimQSj4SrgtEEngEwq4eHFr1sRi5OgVnJvUhO1s9 () mail ! gmail ! com
[Download RAW message or body]

ohhh,, sorry... It was wrong post..sorry again...

On Fri, Oct 29, 2010 at 10:30 AM, Shoaib Mir <shoaibmir@gmail.com> wrote:

> On Fri, Oct 29, 2010 at 3:48 PM, venkat <ven.tammineni@gmail.com> 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/
>

[Attachment #3 (text/html)]

<font color="#000099">ohhh,, sorry... It was wrong post..sorry \
again...<br></font><br><div class="gmail_quote">On Fri, Oct 29, 2010 at 10:30 AM, \
Shoaib Mir <span dir="ltr">&lt;<a \
href="mailto:shoaibmir@gmail.com">shoaibmir@gmail.com</a>&gt;</span> wrote:<br> \
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex;"><div class="im">On Fri, Oct 29, 2010 at 3:48 PM, venkat \
<span dir="ltr">&lt;<a href="mailto:ven.tammineni@gmail.com" \
target="_blank">ven.tammineni@gmail.com</a>&gt;</span> wrote:<br> </div><div \
class="gmail_quote"><div class="im"><blockquote class="gmail_quote" style="margin:0 0 \
0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <font color="#000099">Dear \
All,</font><div><font color="#000099"><br></font></div><div><font color="#000099">  I \
want to convert integer datatype to serial datatype.. is that possible.Please let me \
know.</font></div><div>

<font color="#000099"><br></font></div></blockquote><div><br></div></div><div>I \
don&#39;t think ALTER TABLE will let you do that... so the best way to achieve the \
same is:</div><div><br></div><div>- Create a sequence for the column (set the start \
of sequence according to the values you got already in the column)</div>

<div>- Now set this sequence as the default value for that specific column which you \
need to ALTER like this:</div><div><br></div><div><span style="font-family:arial, \
sans-serif;font-size:12px">ALTER TABLE tablename ALTER COLUMN columnname <br>

        SET DEFAULT nextval(&#39;newsequence&#39;::regclass);</span></div></div><br><font \
color="#888888">-- <br>Shoaib Mir<br><a href="http://shoaibmir.wordpress.com/" \
target="_blank">http://shoaibmir.wordpress.com/</a><br>

</font></blockquote></div><br>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic