Re: Autoformatting

From: Dave Page <dpage(at)pgadmin(dot)org>
To: Robert Eckhardt <reckhardt(at)pivotal(dot)io>
Cc: Shirley Wang <swang(at)pivotal(dot)io>, Raffi Holzer <rholzer(at)pivotal(dot)io>, pgadmin-hackers <pgadmin-hackers(at)postgresql(dot)org>
Subject: Re: Autoformatting
Date: 2017-05-09 08:26:01
Message-ID: CA+OCxoyw+TA8A8nyAD=JSTz4dSyzcMtYMDhzjX1mLxsUe+HgNQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgadmin-hackers

On Mon, May 8, 2017 at 3:50 PM, Robert Eckhardt <reckhardt(at)pivotal(dot)io>
wrote:

> Over the weekend I created some options for formatting. certainly this
> isn't complete but I hope it is a good starting point for the conversation.
> Copy and paste lost syntax highlighting but please assume that will be
> included.
>
> /* Unformatted */
>
> select distinct dep.deptype,dep.classid,coalesce(coc.relname,
> clrw.relname) as
> ownertable from pg_depend dep left join pg_class cl on dep.objid = cl.oid
> left join pg_attribute att on dep.objid = att.attrelid and dep.objsubid =
> att.attnum
> where dep.objid = 16385 :: oid and classid in (select oid from pg_class
> where relname in ( 'pg_class', 'pg_constraint' )) order by
> classid,cl.relkin;
>
>
> /* Keywords Upper, Stacked, commas after */
>
> SELECT DISTINCT dep.deptype,
> dep.classid,
> Coalesce(coc.relname, clrw.relname) AS ownertable
> FROM pg_depend dep
> left join pg_class cl
> ON dep.objid = cl.oid
> left join pg_attribute att
> ON dep.objid = att.attrelid
> AND dep.objsubid = att.attnum
> WHERE dep.objid = 16385 :: oid
> AND classid IN (SELECT oid
> FROM pg_class
> WHERE relname IN ( 'pg_class', 'pg_constraint' ))
> ORDER BY classid,
> cl.relkin;
>

Snipping the rest, as I think 'commas before' are the work of Chthulu.
Aside from the fact that they look ugly, the whole point of a comma is to
denote a pause/separation after a word.

Anyhoo, The standard we try to use in pgAdmin at the moment is slightly
different from the example you've given. To add it into the mix...

/* Keywords Upper, 4 space indent, commas after, AND/OR after,
* no spaces after ( or before ), or around ::
*/
SELECT DISTINCT
dep.deptype,
dep.classid,
coalesce(coc.relname, clrw.relname) AS ownertable
FROM
pg_depend dep
LEFT JOIN pg_class cl ON dep.objid = cl.oid
LEFT JOIN pg_attribute att ON dep.objid = att.attrelid AND dep.objsubid
= att.attnum
WHERE
dep.objid = 16385::oid AND
classid IN (
SELECT
oid
FROM
pg_class
WHERE
relname IN ('pg_class', 'pg_constraint')
)
ORDER BY
classid,
cl.relkind;

There are some subtleties that are open to personal taste there;

- Formatting of the sub-select - e.g. should the SELECT directly follow the
(, and should the rest be indented accordingly?

- Formatting of multiple quals in the joins; e.g. should the qual following
the AND be on the next line, and if so, should it be indented one level, or
to align with the qual above? Should the first qual be on the next line?

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

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

In response to

Responses

Browse pgadmin-hackers by date

  From Date Subject
Next Message Dave Page 2017-05-09 08:26:43 Re: [pgAdmin4][runtime]: RM #2328 - Unable to launch query tool and debugger in new browser tab
Previous Message Akshay Joshi 2017-05-09 08:18:21 Re: [pgAdmin4][runtime]: RM #2328 - Unable to launch query tool and debugger in new browser tab