Search Postgresql Archives

Re: Numbering rows by date

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In article <ft074l$46m$1@xxxxxxxxxxxx>,
"Andrus" <kobruleht2@xxxxxx> writes:

> I have table
> create Document ( docdate date, docorder integer )

> I need update docorder column with numbers 1,2 in docdate date order
> Something like

> i = 1;
> UPDATE Document SET docorder = i++
>   ORDER BY docdate;


> How to do this is PostgreSQL 8.2 ?

I don't think you can avoid a temp table:

CREATE TEMP TABLE tmp (
  docdate date,
  docorder serial
);

INSERT INTO tmp (docdate)
SELECT docdate
FROM documents
ORDER BY docdate;

UPDATE documents d
SET docorder = t.docorder
FROM tmp t
WHERE d.docdate = t.docdate;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux