Re: Cool hack with recursive queries

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Gregory Stark <stark(at)enterprisedb(dot)com>
Cc: Postgres <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Cool hack with recursive queries
Date: 2008-11-23 03:34:21
Message-ID: 20081123033421.GH3813@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Gregory Stark wrote:

> WITH RECURSIVE Z(IX, IY, CX, CY, X, Y, I) AS (
> SELECT IX, IY, X::float, Y::float, X::float, Y::float, 0
> FROM (select -2.2 + 0.031 * i, i from generate_series(0,101) as i) as xgen(x,ix),
> (select -1.5 + 0.031 * i, i from generate_series(0,101) as i) as ygen(y,iy)
> UNION ALL
> SELECT IX, IY, CX, CY, X * X - Y * Y + CX AS X, Y * X * 2 + CY, I + 1
> FROM Z
> WHERE X * X + Y * Y < 16::float
> AND I < 100
> )
> SELECT array_to_string(array_agg(SUBSTRING(' .,,,-----++++%%%%@@@@#### ', LEAST(GREATEST(I,1),27), 1)),'')
> FROM (
> SELECT IX, IY, MAX(I) AS I
> FROM Z
> GROUP BY IY, IX
> ORDER BY IY, IX
> ) AS ZT
> GROUP BY IY
> ORDER BY IY

FWIW you can halve the running time by restricting I to 27 instead of
100 in the recursive term, and obtain the same result.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2008-11-23 03:43:22 Re: portability of "designated initializers"
Previous Message V S P 2008-11-23 03:04:48 [Q]updating multiple rows with Different values