Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZrMdi-0000jY-OE for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Oct 2015 09:03:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZrMdi-0000W8-AN for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Oct 2015 09:03:26 +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) (envelope-from ) id 1ZrMdg-0000UU-27 for pgsql-hackers@postgresql.org; Wed, 28 Oct 2015 09:03:24 +0000 Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZrMdd-00074i-5x for pgsql-hackers@postgresql.org; Wed, 28 Oct 2015 09:03:23 +0000 Received: by wikq8 with SMTP id q8so244195202wik.1 for ; Wed, 28 Oct 2015 02:03:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joh_to.20150623.gappssmtp.com; s=20150623; h=from:subject:to:message-id:date:user-agent:mime-version :content-type; bh=R2VRZCBV9dC0llMzxnc/2koQGlRNtejSBPJzVCNCwo4=; b=O7Pham8ntwjoLZ4Rv0GQdFUEeeki6wx4aY9PqDxsZk+arYz/KLsFRc1Ixx9T5r435Y kP/vQqcwHcTtHiTaRc3AOVIT+AZXfaJmeIY9CmgLJrPWrZ1W8IwSM6tsypLz37P1kYfr 0ZyRH4qvD+9iH/T0knvCXNHxz1MhyZtL2s3upxegYNoMcZKd0sm3dspNYitFZWo71/CS 67fgoHo8ye3VfQ3VLVRuD6diSr6LrE9pZd76k+1FE+P6w3ln1VaE0NF3802FhTTEnvXp aMN8kxPpvKRB0jAZcC5YkURlLvQgfwG8DAEBQo0CegKroS5as3DqicyverOvp/GqGkRj 4wOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version:content-type; bh=R2VRZCBV9dC0llMzxnc/2koQGlRNtejSBPJzVCNCwo4=; b=RmEbNWx+xu7wgOKz5qc6p3WRogpx1npCWGQAhj80/CnBybGx1yzcl/IBwXU5YBZZLz pE47IS1eIXWY/9QT5B14BQlhj0zsjA9mwysBWaCXFgV8oVfSEo8LNLpQ3pyGgwitAlFz TCFuG1fZiNfwFny0lLrlCqBjn8LcZ933ZndTl9pb7KNHZazPaUCUvQgMOiKFNnAtvJEB pEpMBo9y8WPEgbtCurNNDd6bs3Gkt60vznr5fRFNQuO/Nl8Mrh+Hq9VoDAKoIAfcpxOp MA1oYPleLvTzyeZiFqMrEuBBHP+R7G68pkCkyHGJcrSHbl9efrR5afbB2C1T3zGGlNHO nIXA== X-Gm-Message-State: ALoCoQl6P1X1BzgH1PhKT/Mexmqpqt5uR7408hXNigSuEsXTNTvJJtLTHuE/RaqttQX67xSlaPtn X-Received: by 10.180.90.37 with SMTP id bt5mr1642678wib.7.1446022998638; Wed, 28 Oct 2015 02:03:18 -0700 (PDT) Received: from Markos-MacBook-Pro.local ([213.164.8.43]) by smtp.googlemail.com with ESMTPSA id p4sm20263wif.22.2015.10.28.02.03.17 for (version=TLSv1/SSLv3 cipher=OTHER); Wed, 28 Oct 2015 02:03:17 -0700 (PDT) From: Marko Tiikkaja Subject: psql: add \pset true/false To: PostgreSQL hackers Message-ID: <56308F56.8060908@joh.to> Date: Wed, 28 Oct 2015 10:03:18 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------020800010407090901010003" X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is a multi-part message in MIME format. --------------020800010407090901010003 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hello hello, Since the default t/f output for booleans is not very user friendly, attached is a patch which enables you to do for example the following: =# \pset true TRUE Boolean TRUE display is "TRUE". =# \pset false FALSE Boolean FALSE display is "FALSE". =# select true, false; bool | bool ------+------- TRUE | FALSE (1 row) (For anyone reviewing: I didn't touch the parts of describe.c which do this for nullPrint: myopt.nullPrint = NULL; since I thought it was dubious in the first place, and I don't think we output booleans in the describe commands.) .m --------------020800010407090901010003 Content-Type: text/x-patch; name="psqltruefalse_v1.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="psqltruefalse_v1.patch" diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index 212dbfa..2048ba3 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -2229,6 +2229,26 @@ lo_import 152801 + true + + + Sets the string to be printed in place of a boolean TRUE value. + The default is to print a 't' character. + + + + + + false + + + Sets the string to be printed in place of a boolean FALSE value. + The default is to print an 'f' character. + + + + + null diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 5163c76..7fadb0a 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -1151,7 +1151,7 @@ exec_command(const char *cmd, int i; static const char *const my_list[] = { "border", "columns", "expanded", "fieldsep", "fieldsep_zero", - "footer", "format", "linestyle", "null", + "footer", "format", "linestyle", "true", "false", "null", "numericlocale", "pager", "pager_min_lines", "recordsep", "recordsep_zero", "tableattr", "title", "tuples_only", @@ -2591,6 +2591,26 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet) } } + /* boolean TRUE display */ + else if (strcmp(param, "true") == 0) + { + if (value) + { + free(popt->truePrint); + popt->truePrint = pg_strdup(value); + } + } + + /* boolean FALSE display */ + else if (strcmp(param, "false") == 0) + { + if (value) + { + free(popt->falsePrint); + popt->falsePrint = pg_strdup(value); + } + } + /* field separator for unaligned text */ else if (strcmp(param, "fieldsep") == 0) { @@ -2782,6 +2802,20 @@ printPsetInfo(const char *param, struct printQueryOpt *popt) popt->nullPrint ? popt->nullPrint : ""); } + /* show true display */ + else if (strcmp(param, "true") == 0) + { + printf(_("Boolean TRUE display is \"%s\".\n"), + popt->truePrint ? popt->truePrint : "t"); + } + + /* show false display */ + else if (strcmp(param, "false") == 0) + { + printf(_("Boolean FALSE display is \"%s\".\n"), + popt->falsePrint ? popt->falsePrint : "f"); + } + /* show locale-aware numeric output */ else if (strcmp(param, "numericlocale") == 0) { @@ -2953,6 +2987,14 @@ pset_value_string(const char *param, struct printQueryOpt *popt) return psprintf("%s", _align2string(popt->topt.format)); else if (strcmp(param, "linestyle") == 0) return psprintf("%s", get_line_style(&popt->topt)->name); + else if (strcmp(param, "true") == 0) + return pset_quoted_string(popt->truePrint + ? popt->truePrint + : "t"); + else if (strcmp(param, "false") == 0) + return pset_quoted_string(popt->falsePrint + ? popt->falsePrint + : "f"); else if (strcmp(param, "null") == 0) return pset_quoted_string(popt->nullPrint ? popt->nullPrint diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index 5b63e76..d0bf418 100644 --- a/src/bin/psql/help.c +++ b/src/bin/psql/help.c @@ -258,7 +258,7 @@ slashUsage(unsigned short int pager) fprintf(output, _(" \\H toggle HTML output mode (currently %s)\n"), ON(pset.popt.topt.format == PRINT_HTML)); fprintf(output, _(" \\pset [NAME [VALUE]] set table output option\n" - " (NAME := {format|border|expanded|fieldsep|fieldsep_zero|footer|null|\n" + " (NAME := {format|border|expanded|fieldsep|fieldsep_zero|footer|true|false|null|\n" " numericlocale|recordsep|recordsep_zero|tuples_only|title|tableattr|pager|\n" " unicode_border_linestyle|unicode_column_linestyle|unicode_header_linestyle})\n")); fprintf(output, _(" \\t [on|off] show only rows (currently %s)\n"), @@ -371,6 +371,8 @@ helpVariables(unsigned short int pager) fprintf(output, _(" format set output format [unaligned, aligned, wrapped, html, asciidoc, ...]\n")); fprintf(output, _(" footer enable or disable display of the table footer [on, off]\n")); fprintf(output, _(" linestyle set the border line drawing style [ascii, old-ascii, unicode]\n")); + fprintf(output, _(" true set the string to be prined in place of a TRUE value\n")); + fprintf(output, _(" false set the string to be prined in place of a FALSE value\n")); fprintf(output, _(" null set the string to be printed in place of a null value\n")); fprintf(output, _(" numericlocale enable or disable display of a locale-specific character to separate\n" " groups of digits [on, off]\n")); diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c index ad4350e..ba5c651 100644 --- a/src/bin/psql/print.c +++ b/src/bin/psql/print.c @@ -3215,6 +3215,13 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *f cell = format_numeric_locale(cell); mustfree = true; } + else if (PQftype(result, c) == BOOLOID) + { + if (cell[0] == 't' && opt->truePrint) + cell = opt->truePrint; + else if (cell[0] == 'f' && opt->falsePrint) + cell = opt->falsePrint; + } } translate = (opt->translate_columns && opt->translate_columns[c]); diff --git a/src/bin/psql/print.h b/src/bin/psql/print.h index b0b6bf5..7949c18 100644 --- a/src/bin/psql/print.h +++ b/src/bin/psql/print.h @@ -152,6 +152,8 @@ typedef struct printQueryOpt { printTableOpt topt; /* the options above */ char *nullPrint; /* how to print null entities */ + char *truePrint; /* how to print TRUE booleans */ + char *falsePrint; /* how to print FALSE booleans */ bool quote; /* quote all values as much as possible */ char *title; /* override title */ char **footers; /* override footer (default is "(xx rows)") */ --------------020800010407090901010003 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --------------020800010407090901010003--