Re: Cool hack with recursive queries

From: "David Rowley" <dgrowley(at)gmail(dot)com>
To: "'Gregory Stark'" <stark(at)enterprisedb(dot)com>, "'Postgres'" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Cool hack with recursive queries
Date: 2008-11-19 22:21:06
Message-ID: E63D6301D61F4659988453B48A61DE08@amd64
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Gregory Stark wrote:
> So based on Graeme Job's T-SQL hack over at thedailywtf.com I adapted the
> T-SQL code to Postgres and got this. Thought others might find it amusing.
>
> 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
>

That's pretty amazing.

I think we should add a regression test with that. :)

David.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message ITAGAKI Takahiro 2008-11-19 23:51:33 HEAD build failure on win32 mingw
Previous Message Grzegorz Jaskiewicz 2008-11-19 22:17:15 Re: Cool hack with recursive queries