pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Greg Sabino Mullane <greg@turnstep.com>
To: pgsql-sql@postgresql.org
Subject: Re: UPDATE WITH ORDER BY
Date: Wed, 27 Apr 2005 12:05:49 -0000
Message-ID: <f4c00ccf32fdcc228c81c684be9b58d5@biglumber.com> (raw)
In-Reply-To: <426DB1A0.2000604@carvalhaes.net>


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


(Please send email as text, not HTML)

> I need to make an UPDATE on a column reordering it with a sequence
> using order by a description
> ...

BEGIN;
CREATE SEQUENCE fruit_seq;
CREATE TABLE newfruit AS SELECT nextval('fruit_seq')::int AS newid, * FROM fruit ORDER BY lower(description);
ALTER TABLE newfruit DROP COLUMN id;
ALTER TABLE newfruit RENAME COLUMN newid TO id;
DROP TABLE fruit;
ALTER TABLE newfruit RENAME TO fruit;
DROP SEQUENCE fruit_seq;
COMMIT;
SELECT * FROM fruit ORDER BY id ASC;


- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200504270805
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iD8DBQFCb4ArvJuQZxSWSsgRAnSGAJwMbp6qoN3H2wFedsgn8N55kV6zUQCg77Qn
VWsBmACCUFIdzRDRRalG6KI=
=y3G9
-----END PGP SIGNATURE-----





view thread (6+ messages)  latest in thread

Message-ID: <f4c00ccf32fdcc228c81c684be9b58d5@biglumber.com>
Permalink:  ../f4c00ccf32fdcc228c81c684be9b58d5@biglumber.com/
Also on:    postgresql.org/message-id/f4c00ccf32fdcc228c81c684be9b58d5@biglumber.com

 · 

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: greg@turnstep.com
  Subject: Re: UPDATE WITH ORDER BY
  In-Reply-To: <f4c00ccf32fdcc228c81c684be9b58d5@biglumber.com>

* 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