Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ce0kJ-0000U9-Oh for pgadmin-hackers@arkaria.postgresql.org; Wed, 15 Feb 2017 14:39:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ce0kJ-0004V7-Bg for pgadmin-hackers@arkaria.postgresql.org; Wed, 15 Feb 2017 14:39:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ce0kI-0004Uc-Pg for pgadmin-hackers@postgresql.org; Wed, 15 Feb 2017 14:39:50 +0000 Received: from mail-io0-x22d.google.com ([2607:f8b0:4001:c06::22d]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1ce0kF-0004Qv-1A for pgadmin-hackers@postgresql.org; Wed, 15 Feb 2017 14:39:50 +0000 Received: by mail-io0-x22d.google.com with SMTP id l66so90457902ioi.1 for ; Wed, 15 Feb 2017 06:39:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pivotal-io.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=sbNkJSDJztU82ASZFUGYoLlf115vIVaN8ZHqPVZBJVY=; b=pBLe7BEoRjnoSmnCkfjYV757tLO/5uoU5cPy0CXM+1uoccUglThDrI6imvavzgyuUs XZpDzobe+0vOCytm2KhRUsRR/hzHdzMuPQKR1ghmllxkYnI7XyaJq4RBfA9VxrN+ZUJ9 vZmD9cGXb68N1eJfUzj6Y1GI86qcRNQ5mPJ20tt+SgDligOzv7OXfezUSnQDEbl8w4g6 Ht2hHOV6wThDCzpO/sLUzQJ97p7ZvYWiCEFOz8mJFB/TIT9Mq6lInynklrFbc4CsNkah OkpDUiUElQb61jMFY1sK4oUSfmYs/9YcCScr7nc6NXYeILbe943UXqe4ebUbuMnV8E/W Wofg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=sbNkJSDJztU82ASZFUGYoLlf115vIVaN8ZHqPVZBJVY=; b=rol715aY27a9YJEJRhu0KqQ0A1LrPEyAC7wCp6lWO9h3Nf4fsEf0u+YWOhXMVFBDRe T16z19fa3cq64vru9SLp8Ba5+13SAINsTsWCP3kI0kEyLom9Vt5QTyG2Mx+2aoNeCU+1 7sLEuclOu/BA5+36x3PalX/1vskxLY1yHhyZS0fNcAh4YnMiuJGwEfygzb9hBnGF5Rxn EBdxC/Z4v86MlInAp1ReAinaZz52lelas/OD+MhBhXKWgu5Jriefd16ntlQYkUG66h49 D9GfMDLFUyDJQLjrsPf+7GV80xta33zVYWrlnE6P1KR18SQwU8yuTizWN75sb6LcU3Mt WJFw== X-Gm-Message-State: AMke39ltngol4EPpLuNqjwoVyvv+XyQqS/KByARpd/3CmHDwNAG4x00roDRIKQiwH5n69m2B8HdheNTcoa32AbVO X-Received: by 10.107.41.205 with SMTP id p196mr34225958iop.124.1487169584862; Wed, 15 Feb 2017 06:39:44 -0800 (PST) MIME-Version: 1.0 Received: by 10.79.142.21 with HTTP; Wed, 15 Feb 2017 06:39:44 -0800 (PST) In-Reply-To: References: From: Raffi Holzer Date: Wed, 15 Feb 2017 09:39:44 -0500 Message-ID: Subject: Re: Autoformatting To: Dave Page Cc: pgadmin-hackers Content-Type: multipart/alternative; boundary=001a1141efe2d3b2cc054892a668 X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgadmin-hackers Precedence: bulk Sender: pgadmin-hackers-owner@postgresql.org --001a1141efe2d3b2cc054892a668 Content-Type: text/plain; charset=UTF-8 Thanks Dave! We came to the same conclusion about a button press. And thank you for the SQL guidelines. On Wed, Feb 15, 2017 at 4:37 AM, Dave Page wrote: > Hi > > On Tue, Feb 14, 2017 at 3:02 PM, Raffi Holzer wrote: > > Hi Dave, > > When we were talking about auto formatting we were actually referring > to a > > single button press doing all of these things to a large block of text. > The > > use case here would be if you receive a large illegible query and paste > it > > into the query editor it would either automatically auto-format or you > would > > press a button and it would auto-format. > > Oh, OK. > > > We are trying to determine a few > > things. One, are there preferred formatting guidelines > > Hmm, it seems I missed SQL when I wrote our (basic) coding standards: > https://www.pgadmin.org/docs4/1.x/coding_standards.html > > By default (in my opinion), we should have 4 character indents, new > lines for logically distinct objects (e.g. columns or constraints on a > table), commas etc. at the end of the line, keywords in upper case, > e.g. > > SELECT > a, > b, > FROM > t > ORDER BY > a, > b; > > However, that obviously becomes unwieldy in some cases, so common > sense is needed: > > SELECT > a, b, > FROM > t > ORDER BY > a, b; > > There should of course be a limit on the number of columns listed per > line - but should the limit be a count or max width in chars? With a > CREATE TABLE statement I think it's clear that each column should be > on it's own line: > > CREATE TABLE t ( > a serial NOT NULL PRIMARY KEY, > b text > ); > > In other words, we need to define (or adopt) a formal standard for > this, and then write a parser/formatter - which seems like a decidedly > non-trivial amount of work (FYI, I tried the Python format-sql module, > and it failed on ~80% of my tests - probably either because it doesn't > understand COPY or pl/pgsql). > > > and two, how should > > this autoformatting be implemented? On a button press? Upon pasting in > the > > text? > > Definitely not on pasting - if you drop in a large script, it could > take far too long, plus you may not care, or be looking at the > original source in another tool and trying to mentally reconcile lines > or statements to each other. I would say it should be a > button/shortcut. > > -- > Dave Page > Blog: http://pgsnake.blogspot.com > Twitter: @pgsnake > > EnterpriseDB UK: http://www.enterprisedb.com > The Enterprise PostgreSQL Company > -- Raffi Holzer Product Manager Pivotal Labs --001a1141efe2d3b2cc054892a668 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Thanks Dave! We came to the same conclusion about a button= press. And thank you for the SQL guidelines.

On Wed, Feb 15, 2017 at 4:37 AM, Dave Pag= e <dpage@pgadmin.org> wrote:
Hi

On Tue, Feb 14, 2017 at 3:02 PM, Raffi Holzer <rholzer@pivotal.io> wrote:
> Hi Dave,
>=C2=A0 When we were talking about auto formatting we were actually refe= rring to a
> single button press doing all of these things to a large block of text= . The
> use case here would be if you receive a large illegible query and past= e it
> into the query editor it would either automatically auto-format or you= would
> press a button and it would auto-format.

Oh, OK.

> We are trying to determine a few
> things. One, are there preferred formatting guidelines

Hmm, it seems I missed SQL when I wrote our (basic) coding standards= :
https://www.pgadmin.org/docs4/1.x/coding= _standards.html

By default (in my opinion), we should have 4 character indents, new
lines for logically distinct objects (e.g. columns or constraints on a
table), commas etc. at the end of the line, keywords in upper case,
e.g.

SELECT
=C2=A0 =C2=A0 a,
=C2=A0 =C2=A0 b,
FROM
=C2=A0 =C2=A0 t
ORDER BY
=C2=A0 =C2=A0 a,
=C2=A0 =C2=A0 b;

However, that obviously becomes unwieldy in some cases, so common
sense is needed:

SELECT
=C2=A0 =C2=A0 a, b,
FROM
=C2=A0 =C2=A0 t
ORDER BY
=C2=A0 =C2=A0 a, b;

There should of course be a limit on the number of columns listed per
line - but should the limit be a count or max width in chars? With a
CREATE TABLE statement I think it's clear that each column should be on it's own line:

CREATE TABLE t (
=C2=A0 =C2=A0 a serial NOT NULL PRIMARY KEY,
=C2=A0 =C2=A0 b text
);

In other words, we need to define (or adopt) a formal standard for
this, and then write a parser/formatter - which seems like a decidedly
non-trivial amount of work (FYI, I tried the Python format-sql module,
and it failed on ~80% of my tests - probably either because it doesn't<= br> understand COPY or pl/pgsql).

> and two, how should
> this autoformatting be implemented? On a button press? Upon pasting in= the
> text?

Definitely not on pasting - if you drop in a large script, it could<= br> take far too long, plus you may not care, or be looking at the
original source in another tool and trying to mentally reconcile lines
or statements to each other. I would say it should be a
button/shortcut.

--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



--
=
Raffi Holzer
Product Manager
Pivotal Labs
--001a1141efe2d3b2cc054892a668--