Re: Ascii Elephant for text based protocols - Final

From: Victor Yegorov <vyegorov(at)gmail(dot)com>
To: Charles Clavadetscher <clavadetscher(at)swisspug(dot)org>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Ascii Elephant for text based protocols - Final
Date: 2016-05-17 12:25:15
Message-ID: CAGnEboixu4_Zgp7MVURNDKmxVwkK+SAfHU8ofAiq2SHB7g77xQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2016-05-16 14:47 GMT+03:00 Charles Clavadetscher <clavadetscher(at)swisspug(dot)org
>:

> SQL version by Melvin Davidson:
>
> CREATE TABLE elephant
> (row_num integer NOT NULL,
> row_dat varchar(30) NOT NULL,
> CONSTRAINT elephant_pk PRIMARY KEY (row_num)
> );
>
> INSERT INTO elephant
> (row_num, row_dat)
> VALUES
> ( 1,'+------------------------+'),
> ( 2,'| ____ ______ ___ |'),
> ( 3,'| / )/ \/ \ |'),
> ( 4,'| ( / __ _\ ) |'),
> ( 5,'| \ (/ o) ( o) ) |'),
> ( 6,'| \_ (_ ) \ ) _/ |'),
> ( 7,'| \ /\_/ \)/ |'),
> ( 8,'| \/ <//| |\\> |'),
> ( 9,'| _| | |'),
> (10,'| \|_/ |'),
> (11,'| |'),
> (12,'| PostgreSQL 1996-2016 |'),
> (13,'| 20 Years of success |'),
> (14,'+------------------------+');
>
> SELECT row_dat FROM elephant ORDER BY row_num;
>

I had a bit of fun with this SQL version and came up with this query:

WITH src(s) AS (
VALUES
('729472967293732174412176b12173b17111752171927491b1744171b17411217181417211718141734172b191721191724173b1714171912175b17221b1912174b1412178b121715122a172a1b2317d91a172a17f71b1a1912177')
), str AS (
SELECT string_agg(repeat(translate(substr(s, p, 1), '123456789ab',
'(/>)<+ o_|\'), ('x'||lpad(substr(s, p+1, 1), 8, '0'))::bit(32)::int), '')
line
FROM src, generate_series(1, 182, 2) p
)
SELECT substr(line, p, 21) slon FROM str, generate_series(1, 189, 21) p;

--
Victor Y. Yegorov

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Charles Clavadetscher 2016-05-17 12:49:36 Re: Ascii Elephant for text based protocols - Final function proposal
Previous Message Kevin Grittner 2016-05-17 11:30:14 Re: Increased I/O / Writes