pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to Convert Integer to Serial
8+ messages / 3 participants
[nested] [flat]
* How to Convert Integer to Serial
@ 2010-10-29 04:48 venkat <ven.tammineni@gmail.com>
0 siblings, 3 replies; 8+ messages in thread
From: venkat @ 2010-10-29 04:48 UTC (permalink / raw)
To: pgsql-general@postgresql.org; pgsql-sql
Dear All,
I want to convert integer datatype to serial datatype.. is that
possible.Please let me know.
Thanks and Regards,
Ven
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: How to Convert Integer to Serial
@ 2010-10-29 04:58 venkat <ven.tammineni@gmail.com>
parent: venkat <ven.tammineni@gmail.com>
2 siblings, 1 reply; 8+ messages in thread
From: venkat @ 2010-10-29 04:58 UTC (permalink / raw)
To: pgsql-general@postgresql.org; pgsql-sql
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 <ven.tammineni@gmail.com> wrote:
> Dear All,
>
> I want to convert integer datatype to serial datatype.. is that
> possible.Please let me know.
>
> Thanks and Regards,
>
> Ven
>
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [SQL] How to Convert Integer to Serial
@ 2010-10-29 05:00 Shoaib Mir <shoaibmir@gmail.com>
parent: venkat <ven.tammineni@gmail.com>
2 siblings, 1 reply; 8+ messages in thread
From: Shoaib Mir @ 2010-10-29 05:00 UTC (permalink / raw)
To: venkat <ven.tammineni@gmail.com>; +Cc: pgsql-general@postgresql.org; pgsql-sql
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/
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [SQL] How to Convert Integer to Serial
@ 2010-10-29 05:01 Shoaib Mir <shoaibmir@gmail.com>
parent: venkat <ven.tammineni@gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: Shoaib Mir @ 2010-10-29 05:01 UTC (permalink / raw)
To: venkat <ven.tammineni@gmail.com>; +Cc: pgsql-general@postgresql.org; pgsql-sql
On Fri, Oct 29, 2010 at 3:58 PM, venkat <ven.tammineni@gmail.com> 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/
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [SQL] How to Convert Integer to Serial
@ 2010-10-29 05:02 venkat <ven.tammineni@gmail.com>
parent: Shoaib Mir <shoaibmir@gmail.com>
0 siblings, 0 replies; 8+ messages in thread
From: venkat @ 2010-10-29 05:02 UTC (permalink / raw)
To: Shoaib Mir <shoaibmir@gmail.com>; +Cc: pgsql-general@postgresql.org; pgsql-sql
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/
>
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: How to Convert Integer to Serial
@ 2010-10-29 05:09 John R Pierce <pierce@hogranch.com>
parent: venkat <ven.tammineni@gmail.com>
2 siblings, 0 replies; 8+ messages in thread
From: John R Pierce @ 2010-10-29 05:09 UTC (permalink / raw)
To: PostgreSQL <pgsql-general@postgresql.org>
On 10/28/10 9:48 PM, venkat wrote:
> Dear All,
>
> I want to convert integer datatype to serial datatype.. is that
> possible.Please let me know.
>
SERIAL is not actually a data type, its simply an integer with an
associated sequence. what Shoab Mir gave will add this sequence to
the existing integer
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [SQL] How to Convert Integer to Serial
@ 2010-10-29 05:10 Shoaib Mir <shoaibmir@gmail.com>
parent: Shoaib Mir <shoaibmir@gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: Shoaib Mir @ 2010-10-29 05:10 UTC (permalink / raw)
To: venkat <ven.tammineni@gmail.com>; +Cc: Postgres General <pgsql-general@postgresql.org>
On Fri, Oct 29, 2010 at 4:05 PM, venkat <ven.tammineni@gmail.com> wrote:
> ALTER TABLE Demotable ALTER COLUMN gid
> SET DEFAULT nextval('serial'::regclass);
>
>
> It is saying that ..serial does not exist...is that true ?
>
>
>
Please avoid sending emails to the personal email addresses but use the
community mailing lists for that.
For the error you mentioned please follow the steps I mentioned in my last
email as you are doing it the wrong way.
Create a sequence first and then you can assign that sequence to this
column. You can not assign SERIAL like this, it has to be a sequence name in
there.
Shoaib Mir
http://shoaibmir.wordpress.com/
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [SQL] How to Convert Integer to Serial
@ 2010-10-29 05:29 venkat <ven.tammineni@gmail.com>
parent: Shoaib Mir <shoaibmir@gmail.com>
0 siblings, 0 replies; 8+ messages in thread
From: venkat @ 2010-10-29 05:29 UTC (permalink / raw)
To: Shoaib Mir <shoaibmir@gmail.com>; +Cc: Postgres General <pgsql-general@postgresql.org>
Yes Done... Thanks alot...
On Fri, Oct 29, 2010 at 10:40 AM, Shoaib Mir <shoaibmir@gmail.com> wrote:
> On Fri, Oct 29, 2010 at 4:05 PM, venkat <ven.tammineni@gmail.com> wrote:
>
>> ALTER TABLE Demotable ALTER COLUMN gid
>> SET DEFAULT nextval('serial'::regclass);
>>
>>
>> It is saying that ..serial does not exist...is that true ?
>>
>>
>>
> Please avoid sending emails to the personal email addresses but use the
> community mailing lists for that.
>
> For the error you mentioned please follow the steps I mentioned in my last
> email as you are doing it the wrong way.
>
> Create a sequence first and then you can assign that sequence to this
> column. You can not assign SERIAL like this, it has to be a sequence name in
> there.
>
> Shoaib Mir
> http://shoaibmir.wordpress.com/
>
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2010-10-29 05:29 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-10-29 04:48 How to Convert Integer to Serial venkat <ven.tammineni@gmail.com>
2010-10-29 04:58 ` venkat <ven.tammineni@gmail.com>
2010-10-29 05:01 ` Shoaib Mir <shoaibmir@gmail.com>
2010-10-29 05:10 ` Shoaib Mir <shoaibmir@gmail.com>
2010-10-29 05:29 ` venkat <ven.tammineni@gmail.com>
2010-10-29 05:00 ` Shoaib Mir <shoaibmir@gmail.com>
2010-10-29 05:02 ` venkat <ven.tammineni@gmail.com>
2010-10-29 05:09 ` John R Pierce <pierce@hogranch.com>
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