Thread: [pgadmin-hackers] Autoformatting

[pgadmin-hackers] Autoformatting

From
Raffi Holzer
Date:
Hi Hackers,
 We are looking into auto formatting SQL text in the SQL editor. However, some users have expressed that this can be done in different ways. Are there preferences in this community fo rhow autoformatting should be done?

--
Raffi Holzer
Product Manager
Pivotal Labs

Re: [pgadmin-hackers] Autoformatting

From
Dave Page
Date:
Hi

On Mon, Feb 13, 2017 at 9:35 PM, Raffi Holzer <rholzer@pivotal.io> wrote:
> Hi Hackers,
>  We are looking into auto formatting SQL text in the SQL editor. However,
> some users have expressed that this can be done in different ways. Are there
> preferences in this community fo rhow autoformatting should be done?

I think that really depends on the specific feature being discussed.
For example, auto-indentation is very handy, and whilst it (and most
formatting features) should be configurable, I suspect many people
will leave it turned on. On the other hand, something like
auto-upper-casing of keywords may be either automatic, or shortcut
initiated, e.g. hit Ctrl+U to upper-case the word under the cursor.

Perhaps you should start by listing the specific features? For
reference, here's what pgAdmin 3 had:

* The auto-indent feature will automatically indent text to the same
depth as the previous line when you press return.
* Block indent text by selecting two or more lines and pressing the Tab key.
* Block outdent text that has been indented using the current tab
settings using Shift+Tab.
* Comment out SQL by selecting some text and pressing the Control+K.
* Uncomment SQL by selecting some text starting with a comment and
pressing Control+Shift+K.
* Shift the selected text to upper case by pressing Control+U.
* Shift the selected text to lower case by pressing Control+Shift+U.

pgAdmin 4 currently has:

* Auto-indent (not currently possible to disable it)

I'd definitely like to see the rest (and anything else that seems
useful) added, and made configurable where appropriate. I suspect the
only ones that should be truly automatic are auto-indent and and
upper-casing of keywords.

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

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


Re: [pgadmin-hackers] Autoformatting

From
Raffi Holzer
Date:
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. We are trying to determine a few things. One, are there preferred formatting guidelines and two, how should this autoformatting be implemented? On a button press? Upon pasting in the text?

On Tue, Feb 14, 2017 at 5:53 AM, Dave Page <dpage@pgadmin.org> wrote:
Hi

On Mon, Feb 13, 2017 at 9:35 PM, Raffi Holzer <rholzer@pivotal.io> wrote:
> Hi Hackers,
>  We are looking into auto formatting SQL text in the SQL editor. However,
> some users have expressed that this can be done in different ways. Are there
> preferences in this community fo rhow autoformatting should be done?

I think that really depends on the specific feature being discussed.
For example, auto-indentation is very handy, and whilst it (and most
formatting features) should be configurable, I suspect many people
will leave it turned on. On the other hand, something like
auto-upper-casing of keywords may be either automatic, or shortcut
initiated, e.g. hit Ctrl+U to upper-case the word under the cursor.

Perhaps you should start by listing the specific features? For
reference, here's what pgAdmin 3 had:

* The auto-indent feature will automatically indent text to the same
depth as the previous line when you press return.
* Block indent text by selecting two or more lines and pressing the Tab key.
* Block outdent text that has been indented using the current tab
settings using Shift+Tab.
* Comment out SQL by selecting some text and pressing the Control+K.
* Uncomment SQL by selecting some text starting with a comment and
pressing Control+Shift+K.
* Shift the selected text to upper case by pressing Control+U.
* Shift the selected text to lower case by pressing Control+Shift+U.

pgAdmin 4 currently has:

* Auto-indent (not currently possible to disable it)

I'd definitely like to see the rest (and anything else that seems
useful) added, and made configurable where appropriate. I suspect the
only ones that should be truly automatic are auto-indent and and
upper-casing of keywords.

--
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

Re: [pgadmin-hackers] Autoformatting

From
Dave Page
Date:
Hi

On Tue, Feb 14, 2017 at 3:02 PM, Raffi Holzer <rholzer@pivotal.io> 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


Re: [pgadmin-hackers] Autoformatting

From
Raffi Holzer
Date:
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 <dpage@pgadmin.org> wrote:
Hi

On Tue, Feb 14, 2017 at 3:02 PM, Raffi Holzer <rholzer@pivotal.io> 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

Re: [pgadmin-hackers] Autoformatting

From
Shirley Wang
Date:
Hello!

Attached are current designs for SQL autoformatting. This feature is not developed yet, only mockups of a potential solution so technical implementation is still being discussed. Style guide for autoformatting doesn't yet exist either, what's shown is manually formatted by another person.

When a user highlights a section of text, a menu option appears below with the option to autoformat text. 

Not included in this current design:
- other options available when highlighting multiple sections of text
- compacting queries

We're currently testing this design with pgAdmin3 users. Looking to validate with a few more before developing the feature. Let us know your thoughts!

1. Query pasted into text editor
16- unformatted query.png

2. Query highlighted and autoformat option appears
17- query highlighted.png

3. Query formatted
18- formatted query.png
On Wed, Feb 15, 2017 at 9:40 AM Raffi Holzer <rholzer@pivotal.io> wrote:
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 <dpage@pgadmin.org> wrote:
Hi

On Tue, Feb 14, 2017 at 3:02 PM, Raffi Holzer <rholzer@pivotal.io> 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
Attachment

Re: [pgadmin-hackers] Autoformatting

From
Dave Page
Date:
Hi

On Thu, Feb 16, 2017 at 5:19 PM, Shirley Wang <swang@pivotal.io> wrote:
Hello!

Attached are current designs for SQL autoformatting. This feature is not developed yet, only mockups of a potential solution so technical implementation is still being discussed. Style guide for autoformatting doesn't yet exist either, what's shown is manually formatted by another person.

When a user highlights a section of text, a menu option appears below with the option to autoformat text. 

Not included in this current design:
- other options available when highlighting multiple sections of text

Per our discussion yesterday, I think this is my biggest concern. Other examples of options when blocks of text are highlighted are block indent/outdent (we already have indent), and block commenting.
 
- compacting queries

We're currently testing this design with pgAdmin3 users. Looking to validate with a few more before developing the feature. Let us know your thoughts!

I have a couple more:

- I think the popup control panel should be in a different colour to the highlight color. Maybe the light blue we use on the bootstrap panels.

- Please ensure the formatting code is a implemented in a way that allows easy re-use. I'd like to be able to use it on the SQL and mSQL panels for example, to ensure consistent formatting for display which can be very hard to achieve in the templates alone.

- I would suggest starting a mailing list thread with a rough draft of the intended formatting rules. We can refine them together, and include them in the docs as well as implemented in the code.

Thanks!
 

1. Query pasted into text editor
16- unformatted query.png

2. Query highlighted and autoformat option appears
17- query highlighted.png

3. Query formatted
18- formatted query.png

On Wed, Feb 15, 2017 at 9:40 AM Raffi Holzer <rholzer@pivotal.io> wrote:
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 <dpage@pgadmin.org> wrote:
Hi

On Tue, Feb 14, 2017 at 3:02 PM, Raffi Holzer <rholzer@pivotal.io> 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



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

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

Re: [pgadmin-hackers] Autoformatting

From
Shirley Wang
Date:
Hello!

We're starting development on this soon, so pulling this thread back up.

Here is an update on the design of the pop up, which matches the style we decided for alerts.
autoformating-bluepopup.png
formatted query.png

On Fri, Feb 17, 2017 at 4:32 AM Dave Page <dpage@pgadmin.org> wrote:
Hi

On Thu, Feb 16, 2017 at 5:19 PM, Shirley Wang <swang@pivotal.io> wrote:
Hello!

Attached are current designs for SQL autoformatting. This feature is not developed yet, only mockups of a potential solution so technical implementation is still being discussed. Style guide for autoformatting doesn't yet exist either, what's shown is manually formatted by another person.

When a user highlights a section of text, a menu option appears below with the option to autoformat text. 

Not included in this current design:
- other options available when highlighting multiple sections of text

Per our discussion yesterday, I think this is my biggest concern. Other examples of options when blocks of text are highlighted are block indent/outdent (we already have indent), and block commenting.

I think these can be added in the future, but for now, we should focus on this one and establish a precedent for shortcut pop ups. It will be easier for contributors to add other options with this styling later when they want to, plus we'll get some additional validation that this location/color/copy works.
 
 
- compacting queries

We're currently testing this design with pgAdmin3 users. Looking to validate with a few more before developing the feature. Let us know your thoughts!

I have a couple more:

- I think the popup control panel should be in a different colour to the highlight color. Maybe the light blue we use on the bootstrap panels.

- Please ensure the formatting code is a implemented in a way that allows easy re-use. I'd like to be able to use it on the SQL and mSQL panels for example, to ensure consistent formatting for display which can be very hard to achieve in the templates alone.

- I would suggest starting a mailing list thread with a rough draft of the intended formatting rules. We can refine them together, and include them in the docs as well as implemented in the code.


Yes! We'll do that. 
Attachment

Re: [pgadmin-hackers] Autoformatting

From
Dave Page
Date:


On Thu, May 4, 2017 at 7:58 PM, Shirley Wang <swang@pivotal.io> wrote:
Hello!

We're starting development on this soon, so pulling this thread back up.

Here is an update on the design of the pop up, which matches the style we decided for alerts.
autoformating-bluepopup.png


I like it!
 

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

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

Re: [pgadmin-hackers] Autoformatting

From
Robert Eckhardt
Date:
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; 
 
 /* Keywords Upper, Stacked, commas before */         
          
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, indent = 2 spaces, commas before */  

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, indent = \t, commas before */  
 
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; 


On Fri, May 5, 2017 at 4:38 AM, Dave Page <dpage@pgadmin.org> wrote:


On Thu, May 4, 2017 at 7:58 PM, Shirley Wang <swang@pivotal.io> wrote:
Hello!

We're starting development on this soon, so pulling this thread back up.

Here is an update on the design of the pop up, which matches the style we decided for alerts.
autoformating-bluepopup.png


I like it!
 

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

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

Attachment

Re: [pgadmin-hackers] Autoformatting

From
Dave Page
Date:


On Mon, May 8, 2017 at 3:50 PM, Robert Eckhardt <reckhardt@pivotal.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

Re: [pgadmin-hackers] Autoformatting

From
Robert Eckhardt
Date:


On Tue, May 9, 2017 at 4:26 AM, Dave Page <dpage@pgadmin.org> wrote:

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

Sorry I let this linger. Let's go with the style you currently have. With respect to your additional comments. 

- Sub-Select should be a new line and indented as in your example.
- For multiple quals in the joins; the qual following the AND should be on the next line, and should it be indented one level

-- Rob

Re: [pgadmin-hackers] Autoformatting

From
Dave Page
Date:
On Sun, May 28, 2017 at 11:54 AM, Robert Eckhardt <reckhardt@pivotal.io> wrote:
>
>
> On Tue, May 9, 2017 at 4:26 AM, Dave Page <dpage@pgadmin.org> wrote:
>>
>>
>> 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
>
>
> Sorry I let this linger. Let's go with the style you currently have. With
> respect to your additional comments.

To be clear, I wasn't insisting on that style - but it is (roughly)
what we try to use and what I prefer.

>
> - Sub-Select should be a new line and indented as in your example.

Sounds good.

> - For multiple quals in the joins; the qual following the AND should be on
> the next line, and should it be indented one level

OK.

Thanks!


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

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


Re: [pgadmin-hackers] Autoformatting

From
Murtuza Zabuawala
Date:
Hello,

Just curious to know if we are still working on this feature? 

--
Regards,
Murtuza

On Mon, May 29, 2017 at 5:21 AM, Dave Page <dpage@pgadmin.org> wrote:
On Sun, May 28, 2017 at 11:54 AM, Robert Eckhardt <reckhardt@pivotal.io> wrote:
>
>
> On Tue, May 9, 2017 at 4:26 AM, Dave Page <dpage@pgadmin.org> wrote:
>>
>>
>> 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
>
>
> Sorry I let this linger. Let's go with the style you currently have. With
> respect to your additional comments.

To be clear, I wasn't insisting on that style - but it is (roughly)
what we try to use and what I prefer.

>
> - Sub-Select should be a new line and indented as in your example.

Sounds good.

> - For multiple quals in the joins; the qual following the AND should be on
> the next line, and should it be indented one level

OK.

Thanks!


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

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


--
Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Re: [pgadmin-hackers] Autoformatting

From
Jing Li
Date:
a {word-wrap:normal;word-break:break-word;}.background-contain {background-size:contain;}@media only screen and (max-width:600px) {.container {-webkit-text-size-adjust:none !important;}.container,.palm-one-whole {width:100% !important;min-width:100% !important;}.palm-one-half {width:50% !important;min-width:50% !important;box-sizing:border-box;}blockquote .container,blockquote .container div,blockquote .container table {width:auto !important;min-width:0 !important;position:relative !important;}img {max-width:100%;}.border-outer,.border-middle,.border-inner,.inner,[title="separator"] {width:100% !important;}.innercell {padding:8px !important;}.palm-block {display:block !important;}td.palm-one-whole {display:inline-block !important;padding:0;}td.palm-one-whole:first-child:not(:only-child) {margin-bottom:16px;}td.hostname {padding-top:3px !important;}}@media only screen and (min-width:601px) {.preview-card {max-width:600px !important;}}@media only screen and (min-device-width :320px) and (max-device-width :568px),only screen and (min-device-width :768px) and (max-device-width :1024px),only screen and (max-device-width:640px),only screen and (max-device-width:667px),only screen and (max-width:480px){.container {width:100% !important;min-width:100% !important;}.p,.small,li,font[size="2"],font[size="3"] {font-size:1em !important;}}@media only screen and (min-device-width :320px) and (max-device-width :568px),only screen and (min-device-width :768px) and (max-device-width :1024px),only screen and (min-device-width :1224px) {.message-wrapper {padding-top:6px;}.apple-only[style] {display:block !important;max-height:none !important;line-height:normal !important;overflow:visible !important;height:auto !important;width:100% !important;position:relative !important;}.no-apple {display:none !important;}form {font-size:inherit;}input[type="text"] {height:43px;padding-left:4px !important;}button:hover {cursor:pointer;}}@media only screen and (min-device-width :1224px) {.apple-mail-form {display:block !important;background-color:white !important;}}* [office365] .outlook-com-hidden {display:none !important;}* [office365] .outlook-com-button {display:block;}* [office365] .outlook-com-only {display:block !important;max-height:none !important;line-height:normal !important;overflow:visible !important;height:auto !important;width:100% !important;position:relative !important;}.ExternalClass {width:100%;}.ExternalClass .outlook-com-button {display:block;}.ExternalClass button {height:auto;}.ExternalClass .outlook-com-hidden {display:none !important;}.ExternalClass .outlook-com-only {display:block !important;max-height:none !important;line-height:normal !important;overflow:visible !important;height:auto !important;width:100% !important;position:relative !important;}.ExternalClass .ecxlabels {display:none !important;}.ExternalClass .ecxlabels {display:none !important;}.ExternalClass .ecxarrow {display:none !important;}.ExternalClass cite >div + div {padding:0 0 4px 0;}.ExternalClass .h1 {padding-bottom:5px;}.ExternalClass .h2 {padding-bottom:5px;}.ExternalClass .h3 {padding-bottom:5px;}.ExternalClass [lang="brand-pinterest"] {width:280px !important;}
Hi Murtuza,

We had to put the autoformatting feature on hold for a while to focus on some greenplum work. We have a library in progress but we're not currently far enough along with this to submit a patch.

Thanks,
~Jing



On Wed, Sep 13, 2017 1:13 AM, Murtuza Zabuawala murtuza.zabuawala@enterprisedb.com wrote:
Hello,

Just curious to know if we are still working on this feature? 

--
Regards,
Murtuza

On Mon, May 29, 2017 at 5:21 AM, Dave Page <dpage@pgadmin.org> wrote:
On Sun, May 28, 2017 at 11:54 AM, Robert Eckhardt <reckhardt@pivotal.io> wrote:
>
>
> On Tue, May 9, 2017 at 4:26 AM, Dave Page <dpage@pgadmin.org> wrote:
>>
>>
>> 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
>
>
> Sorry I let this linger. Let's go with the style you currently have. With
> respect to your additional comments.

To be clear, I wasn't insisting on that style - but it is (roughly)
what we try to use and what I prefer.

>
> - Sub-Select should be a new line and indented as in your example.

Sounds good.

> - For multiple quals in the joins; the qual following the AND should be on
> the next line, and should it be indented one level

OK.

Thanks!


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

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


--
Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers