Search Postgresql Archives

Re: Numbering rows by date

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

 



On Wed, 2 Apr 2008, "Andrus" <kobruleht2@xxxxxx> writes:
> 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;

CREATE SEQUENCE document_docorder_seq START 1;

UPDATE document
   SET docorder = T.docorder
  FROM (SELECT nextval('document_docorder_seq') AS docorder, docdate
          FROM document
         ORDER BY docdate) AS T
 WHERE document.docdate = T.docdate;

DROP SEQUENCE document_docorder_seq;


Regards.


[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