Re: [GENERAL] Numbering rows

2008-10-16 Thread Tom Lane
"Richard Broersma" <[EMAIL PROTECTED]> writes: > I looked for ROW_NUMBER in the developer docs. I could only find it > under the KEY WORDS list. I guess they haven't put in a good example > yet. > I saw this recently demonstrated at PgWest by Dave Fetter. He > illustrated several example of how

Re: [GENERAL] Numbering rows

2008-10-16 Thread Richard Broersma
On Wed, Oct 15, 2008 at 10:21 PM, A. Kretschmer <[EMAIL PROTECTED]> wrote: > > Can you show an example for 8.4? I looked for ROW_NUMBER in the developer docs. I could only find it under the KEY WORDS list. I guess they haven't put in a good example yet. I saw this recently demonstrated at PgWes

Re: [GENERAL] Numbering rows

2008-10-16 Thread Mark Morgan Lloyd
David Rowley wrote: It's not 100% certain that it will be possible for 8.4, probably though. select row_number() over (order by employeeid) as nrow,* from employee order by employeeid That makes sense, thanks. So extracting rate-of-change etc. would be a join on two subselects followed by a

Re: [GENERAL] Numbering rows

2008-10-15 Thread David Rowley
Andreas Kretschmer wrote: > Can you show an example for 8.4? It's not 100% certain that it will be possible for 8.4, probably though. select row_number() over (order by employeeid) as nrow,* from employee order by employeeid It's important to have both the order bys There is more information on

Re: [GENERAL] Numbering rows

2008-10-15 Thread A. Kretschmer
am Wed, dem 15.10.2008, um 12:23:42 -0700 mailte Richard Broersma folgendes: > On Wed, Oct 15, 2008 at 12:08 PM, ries van Twisk <[EMAIL PROTECTED]> wrote: > > May be this function can help : > > > > http://www.postgresql.org/docs/8.3/static/functions-srf.html > > Using generate series won't numbe

Re: [GENERAL] Numbering rows

2008-10-15 Thread Mark Morgan Lloyd
D. Dante Lorenso wrote: PERL can remember variables in your session. Here's a function I wrote that sets a "global" variable in PL/PERL: Perl can do anything- that's cheating :-) Actually, I use Perl heavily but the advantage of being able to do the sort of analysis being discussed in a sin

Re: [GENERAL] Numbering rows

2008-10-15 Thread D. Dante Lorenso
Mark Morgan Lloyd wrote: Is there an easy way to assign a sequential number, possibly based on an arbitrary minimum (typically 0 or 1) to each row of an ordered result set, or do I have to work with explicit sequences? I need to do quite a lot of maths on successive rows, extracting numeric a

Re: [GENERAL] Numbering rows

2008-10-15 Thread Mark Morgan Lloyd
Thanks everybody- I'm watching with a lot of interest. I was worried that I was asking something stupid with an obvious answer... ries van Twisk wrote: May be this function can help : http://www.postgresql.org/docs/8.3/static/functions-srf.html Thanks, that's already turning out to be useful

Re: [GENERAL] Numbering rows

2008-10-15 Thread Richard Broersma
On Wed, Oct 15, 2008 at 12:32 PM, Scott Marlowe <[EMAIL PROTECTED]> wrote: > Can't you put the query into a subselect with an offset 0 and join to > that to get the generate_series to work correctly? I've never heard of doing it that way, but I'm very interestes in seeing how it is done. This i

Re: [GENERAL] Numbering rows

2008-10-15 Thread Scott Marlowe
On Wed, Oct 15, 2008 at 1:23 PM, Richard Broersma <[EMAIL PROTECTED]> wrote: > On Wed, Oct 15, 2008 at 12:08 PM, ries van Twisk <[EMAIL PROTECTED]> wrote: >> May be this function can help : >> >> http://www.postgresql.org/docs/8.3/static/functions-srf.html > > Using generate series won't number the

Re: [GENERAL] Numbering rows

2008-10-15 Thread Richard Broersma
On Wed, Oct 15, 2008 at 12:08 PM, ries van Twisk <[EMAIL PROTECTED]> wrote: > May be this function can help : > > http://www.postgresql.org/docs/8.3/static/functions-srf.html Using generate series won't number the rows that way that you would want. You basically will end up with a cross join betw

Re: [GENERAL] Numbering rows

2008-10-15 Thread ries van Twisk
May be this function can help : http://www.postgresql.org/docs/8.3/static/functions-srf.html Ries On Oct 15, 2008, at 1:44 PM, Mark Morgan Lloyd wrote: Is there an easy way to assign a sequential number, possibly based on an arbitrary minimum (typically 0 or 1) to each row of an ordered res

Re: [GENERAL] Numbering rows by date

2008-04-08 Thread Andrus
Volkan, > 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 documen

Re: [GENERAL] Numbering rows by date

2008-04-06 Thread Volkan YAZICI
On Wed, 2 Apr 2008, "Andrus" <[EMAIL PROTECTED]> 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_doc

Re: [GENERAL] Numbering rows by date

2008-04-06 Thread Harald Fuchs
In article <[EMAIL PROTECTED]>, "Andrus" <[EMAIL PROTECTED]> 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; >

Re: [GENERAL] Numbering rows by date

2008-04-05 Thread brian
Andrus wrote: 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 ? ALTER TABLE DROP COLUMN docord