Is this query possible in PostgreSQL ?

Started by Ben-Nes Michaelover 23 years ago3 messagesgeneral
Jump to latest
#1Ben-Nes Michael
miki@canaan.co.il

Hi All

While reading some SQL books i crossed on SUBSETS querry, but it seems
postgres dont understand them.

Is there another way to do this in postgres ?
if so, where i can read about it ?

SELECT * from some_table WHERE MOD(some_row, :n) = 0;

Thanks in advance

#2Bruce Momjian
bruce@momjian.us
In reply to: Ben-Nes Michael (#1)
Re: Is this query possible in PostgreSQL ?

Ben-Nes Michael wrote:

Hi All

While reading some SQL books i crossed on SUBSETS querry, but it seems
postgres dont understand them.

Is there another way to do this in postgres ?
if so, where i can read about it ?

SELECT * from some_table WHERE MOD(some_row, :n) = 0;

So this allows you to get every Xth result, like every 3rd row. Wow,
that is interesting. We don't have a ROWNUM like Oracle has, but if we
did you could just use mod on that:

ROWNUM % 3 = 0

You could use a cursor and fetch only every Xth row. Not sure what else
I can suggest.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#2)
Re: Is this query possible in PostgreSQL ?

Bruce Momjian <pgman@candle.pha.pa.us> writes:

SELECT * from some_table WHERE MOD(some_row, :n) = 0;

So this allows you to get every Xth result, like every 3rd row. Wow,
that is interesting.

s/interesting/useless/. Every third row in what ordering? And don't
tell me about ORDER BY, because WHERE conditions are processed before
ORDER BY.

regards, tom lane