pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-sql@postgresql.org
Subject: Re: Finding Max Value in a Row
Date: Fri, 11 May 2012 21:44:03 +0200
Message-ID: <jojq4e$ogj$1@dough.gmane.org> (raw)
In-Reply-To: <CAAQLLO7-O26xpisutPoud__iDaco6WtZCr6CBG5OgiwpgvWd6g@mail.gmail.com>
References: <CAAQLLO6EhUi0OUi38BiH+qmgKqY+mY27_hGBQJiC5rbWorXQbw@mail.gmail.com>
<00ee01cd2fab$1b528b80$51f7a280$@yahoo.com>
<CAAQLLO7-O26xpisutPoud__iDaco6WtZCr6CBG5OgiwpgvWd6g@mail.gmail.com>
Carlos Mennens wrote on 11.05.2012 21:30:
> Thanks for all the help thus far everyone! I sadly didn't
> create/design the table and would love to create a SEQUENCE on that
> particular field but not sure how unless I DROP the table and create
> from scratch.
>
> Currently the data TYPE on the primary key field (users_id) is CHAR
> and I have no idea why...it should be NUMERIC or SERIAL but it's not
> so my question is if I want to ALTER the column and create a sequence,
> would I simply do:
>
> ALTER TABLE users
> ALTER COLUMN users_id TYPE serial
> ;
>
> Obviously if any of the data stored in users_id is actual CHAR, I'm
> guessing the database would reject that request to change type as the
> existing data would match. However the data type is CHAR but the field
> values are all numeric from 1000000010 - 1000000301 so I'm hoping that
> would work for SERIAL which is just INTEGER, right?
Use this:
alter table users
alter column users_id type integer using to_number(users_id, '99999');
(Adjust the '99999' to the length of the char column)
Then create and "assign" the new sequence as I have shown in my other post.
view thread (18+ messages) latest in thread
Message-ID: <jojq4e$ogj$1@dough.gmane.org> Permalink: ../jojq4e$ogj$1@dough.gmane.org/ Also on: postgresql.org/message-id/jojq4e$ogj$1@dough.gmane.org ·
reply
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Reply to all the recipients using the --to and --cc options: reply via email To: pgsql-sql@postgresql.org Cc: spam_eater@gmx.net Subject: Re: Finding Max Value in a Row In-Reply-To: <jojq4e$ogj$1@dough.gmane.org> * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox
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