Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cdw1j-0005AL-Pk for pgadmin-hackers@arkaria.postgresql.org; Wed, 15 Feb 2017 09:37:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cdw1j-0000rL-4a for pgadmin-hackers@arkaria.postgresql.org; Wed, 15 Feb 2017 09:37:31 +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 1cdw1V-0000cX-EA for pgadmin-hackers@postgresql.org; Wed, 15 Feb 2017 09:37:17 +0000 Received: from mail-it0-x22f.google.com ([2607:f8b0:4001:c0b::22f]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cdw1S-0006c2-8M for pgadmin-hackers@postgresql.org; Wed, 15 Feb 2017 09:37:16 +0000 Received: by mail-it0-x22f.google.com with SMTP id 203so61594222ith.0 for ; Wed, 15 Feb 2017 01:37:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pgadmin-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=90I8hjgC5wLG/1FdWDq2/GqPaVFAiSMRt9Vvi8aZfBU=; b=ibe28uZ1YlQ5F35aFe0ifDiDT5NmiZHIzsV1Byv6lWCbwk42qqgZO6QryJgC7Mv0Ik lzDLtpwQ58TXYaTiqMF9NjXZAZvJa2Y9CAVX6ABs8F9UQBFmuLz5lSilrWHpt3eiNJq0 R9zUGVOqVo3+YUt5ZFAkmj4Lybl5Po9WzeLF1p2YmvyNnRfVUXmtDPVBviUb6hWi0MPZ 9eeYILpGTT0dGbCeLd114XA4DTxMj0ILapWYWZfbCSUBRb80TLk3nngAfRXO+vrfMnXy 9jFzDwP/7pNl2T+P/R0kW6BX7qjq/029SaE0J9DD80rE0UP4h/6bQlm36uGLC8CZP7mO nuwA== 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=90I8hjgC5wLG/1FdWDq2/GqPaVFAiSMRt9Vvi8aZfBU=; b=psglOcIWv1nCzTIztQq8ncvDJ5zLFADsjZBucieyiZuhY2nz+ZkOVTrPYXgbpQ+KmH jPJInyUyXW77ywgUXpnUvJVcZ9tPsweK+xwZFSo7QKfxu3Su1RdVOzYRqCgrUlpyHEGt ZOUBTktUw1uQJILUIWsWzchTOiRkNB0700tw7lOhQlBTDgvXFXpR4Vxyxh/D4SMrzjFE 6PIAqxBRdf07Z8utJ5SEZbRdwpksKWVi7+/TUJ+ozMus2l3g9qfs06N8Mb17wdmoXBCa wYmJ/QnDx1vQeJ2z9yOjXBSoeIDFktjsq1qO8FpSgB3+a87yZI547tSDFfYM24HH1GvR yxEw== X-Gm-Message-State: AMke39k4U/Mp0+ozIThBVt3sUY7monmTV/2fT5EPNCRZANvjRMHzFZnWJsKPwvEGahLBIr8jpCJUiMa/qt49bQ== X-Received: by 10.36.39.78 with SMTP id g75mr7737667ita.94.1487151432409; Wed, 15 Feb 2017 01:37:12 -0800 (PST) MIME-Version: 1.0 Received: by 10.64.224.198 with HTTP; Wed, 15 Feb 2017 01:37:11 -0800 (PST) In-Reply-To: References: From: Dave Page Date: Wed, 15 Feb 2017 09:37:11 +0000 Message-ID: Subject: Re: Autoformatting To: Raffi Holzer Cc: pgadmin-hackers Content-Type: text/plain; charset=UTF-8 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 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 -- Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgadmin-hackers