Instantly share code, notes, and snippets.

Embed
What would you like to do?
with recursive
limitxy AS (SELECT * FROM (VALUES(20, 20)) AS t (x,y)),
formula(n, x, y, c) AS (
VALUES(0, 0, 0, '')
UNION ALL
SELECT n+1,
(SELECT x FROM (SELECT n % (SELECT x FROM limitxy) AS x, n / (SELECT x FROM limitxy) AS y) AS xy),
(SELECT y FROM (SELECT n % (SELECT x FROM limitxy) AS x, n / (SELECT x FROM limitxy) AS y) AS xy),
CASE WHEN (
SELECT (abs(point.x * point.x + point.y * point.y - 80) < 8)    -- 条件式
FROM (
SELECT x - (SELECT x/2 FROM limitxy) AS x, y - (SELECT y/2 FROM limitxy) AS y
FROM (SELECT n % (SELECT x FROM limitxy) AS x, n / (SELECT y FROM limitxy) AS y) AS xy
) AS point
)
then '*'
ELSE ' '
END
FROM formula WHERE n < (SELECT x * y FROM limitxy)
),
mkstring(num, s) AS(
VALUES(0, '')
UNION ALL
SELECT num + 1, (SELECT ARRAY_TO_STRING(ARRAY_AGG(c), '') FROM formula WHERE num = formula.y) FROM mkstring WHERE num < (SELECT y FROM limitxy)
)
SELECT s FROM mkstring WHERE num != 0;
s
----------------------
*****
** **
** **
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
** **
** **
*****
(20 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment