Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 135709FA0E4 for ; Mon, 1 Oct 2007 12:24:06 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 27896-01 for ; Mon, 1 Oct 2007 12:24:02 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.226]) by postgresql.org (Postfix) with ESMTP id 0AA0A9FA0CD for ; Mon, 1 Oct 2007 12:24:01 -0300 (ADT) Received: by nz-out-0506.google.com with SMTP id l8so2322181nzf for ; Mon, 01 Oct 2007 08:24:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; bh=j3iYcEnmPOeWSMAPLwdOw0z8B94zhx9p5d5PPBWUMlc=; b=dIKQb50crb+nO/4BzpY68H0in4n9IF31/Ig2Uew6uZiFV0JG70+ryzNgPDzOvoONSO7rLBbqWP41ZdfCzEIqkEdT1ZZqvAgF4lBW7LE5e+Tz0rSgs/vtpj53uTe192sL0VWTBtUo8qOnEGlYAA3nH9Pv2C1eg+OfPJMGXnpewVY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=e8mQHLLghHDwpt0kRFyVaSTTQmy2OxZY4uImosOCUrzqam6RMoXdTrjvAr3flKgSarIKDd+bOoAj46Pt+tZO0Hp33r76xPSFOvLFyPB2UJNLuVxELHbhyMWx9/k9rtRNbIB1RPCroLfUsnnqpkpbRMG15Qt+hiBXIb0rO6l4JS8= Received: by 10.114.75.1 with SMTP id x1mr716167waa.1191252240476; Mon, 01 Oct 2007 08:24:00 -0700 (PDT) Received: by 10.35.52.15 with HTTP; Mon, 1 Oct 2007 08:24:00 -0700 (PDT) Message-ID: <4f4c2a010710010824t7a2fbd59kb9102c879b389a5d@mail.gmail.com> Date: Mon, 1 Oct 2007 11:24:00 -0400 From: "Jon Horsman" To: "sql pgsql" Subject: Populate unique column with default value MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/1 X-Sequence-Number: 29373 Hey, I'm updating the user table in our db to have a new column "username" as follows. ALTER TABLE usertable ADD COLUMN username varchar(64) UPDATE usertable SET username='' WHERE username ISNULL ALTER TABLE usertable ALTER COLUMN username SET NOT NULL ALTER TABLE usertable ADD CONSTRAINT usertable_username_key UNIQUE(username) I want to essentially do what i have above but need to populate the username field with some unique value so that the last ALTER will run. I have another column in this table that is unique, an phone extension, and am hoping to use this as a default username. Is there an elegant way i can set the username to be the extension of the current row or should i just write a little loop that goes threw and populates my username with the users extension manually for each user in my db and then run the last ALTER. Thanks, Jon.