From: Bruce Momjian <bruce@momjian.us>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Thom Brown <thom@linux.com>
Cc: pgsql-committers <pgsql-committers@postgresql.org>
Subject: Re: pgsql: Allow empty target list in SELECT.
Date: Fri, 20 Mar 2015 08:25:50 -0400
Message-ID: <20150320122550.GH6317@momjian.us> (raw)
In-Reply-To: <28123.1414009150@sss.pgh.pa.us>
References: <E1Vs0Qu-0004bC-6E@gemulon.postgresql.org>
<CAA-aLv4mBXOgbSBPhLPa7sqS6PryihFFb_pzQ7Ue07Oci5g3sQ@mail.gmail.com>
<27441.1414007839@sss.pgh.pa.us>
<CAA-aLv7SjOkt-09Fh8gwh_YQD3B4EcAxzLh7XLyeh9tvKtMwHw@mail.gmail.com>
<CAA-aLv47DpdU5HToNQGuw6Zh74BXU3poACW=nH_FK4qmc73N+w@mail.gmail.com>
<28123.1414009150@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>
On Wed, Oct 22, 2014 at 04:19:10PM -0400, Tom Lane wrote:
> Thom Brown <thom@linux.com> writes:
> > I can see the same output as you if I get it to ignore my .psqlrc file:
>
> > # select * from colours2;
> > --
> > (5 rows)
>
> > Turns out it's "\x auto" causing it.
>
> Ah. Seems like a bug in the expanded-mode printout logic then.
> But, in any case, it's been like that a very long time. You
> could do this at least as far back as 8.4:
>
> regression=# create table foo();
> CREATE TABLE
> regression=# insert into foo default values;
> INSERT 0 1
> regression=# insert into foo default values;
> INSERT 0 1
> regression=# select * from foo;
> --
> (2 rows)
>
> regression=# \x on
> Expanded display is on.
> regression=# select * from foo;
> (No rows)
I have developed a patch to fix this, e.g.:
test=> select * from foo;
--
(2 rows)
test=> \x
Expanded display is on.
test=> select * from foo;
(2 rows)
I used the same footer function every other output format was using.
Patch attached.
I also found that the normal non-expanded output was forcing the use of
a pager for these tests, which seemed odd considering there were no
rows. The problem is that the variable col_count is an unsigned integer,
and there were a few places we were subtracting one from it. When
col_count was zero, subtracting one returned a very larger positive
number, and triggered the pager. That is fixed in this patch as well.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ Everyone has their own god. +
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committersAttachments:psql.diff (text/x-diff, 3.4K) downloaddiff --git a/src/bin/psql/print.c b/src/bin/psql/print.cnew file mode 100644index ce0d05d..40e5098
*** a/src/bin/psql/print.c
--- b/src/bin/psql/print.c
*************** print_aligned_text(const printTableConte
*** 692,698 ****
if (opt_border == 0)
width_total = col_count;
else if (opt_border == 1)
! width_total = col_count * 3 - 1;
else
width_total = col_count * 3 + 1;
total_header_width = width_total;
--- 692,698 ----
if (opt_border == 0)
width_total = col_count;
else if (opt_border == 1)
! width_total = col_count * 3 - ((col_count > 0) ? 1 : 0);
else
width_total = col_count * 3 + 1;
total_header_width = width_total;
*************** print_aligned_text(const printTableConte
*** 928,934 ****
fputs(!header_done[i] ? format->header_nl_right : " ",
fout);
! if (opt_border != 0 && i < col_count - 1)
fputs(dformat->midvrule, fout);
}
curr_nl_line++;
--- 928,934 ----
fputs(!header_done[i] ? format->header_nl_right : " ",
fout);
! if (opt_border != 0 && col_count > 0 && i < col_count - 1)
fputs(dformat->midvrule, fout);
}
curr_nl_line++;
*************** print_aligned_text(const printTableConte
*** 983,989 ****
struct lineptr *this_line = &col_lineptrs[j][curr_nl_line[j]];
int bytes_to_output;
int chars_to_output = width_wrap[j];
! bool finalspaces = (opt_border == 2 || j < col_count - 1);
/* Print left-hand wrap or newline mark */
if (opt_border != 0)
--- 983,990 ----
struct lineptr *this_line = &col_lineptrs[j][curr_nl_line[j]];
int bytes_to_output;
int chars_to_output = width_wrap[j];
! bool finalspaces = (opt_border == 2 ||
! (col_count > 0 && j < col_count - 1));
/* Print left-hand wrap or newline mark */
if (opt_border != 0)
*************** print_aligned_text(const printTableConte
*** 1077,1087 ****
fputs(format->wrap_right, fout);
else if (wrap[j] == PRINT_LINE_WRAP_NEWLINE)
fputs(format->nl_right, fout);
! else if (opt_border == 2 || j < col_count - 1)
fputc(' ', fout);
/* Print column divider, if not the last column */
! if (opt_border != 0 && j < col_count - 1)
{
if (wrap[j + 1] == PRINT_LINE_WRAP_WRAP)
fputs(format->midvrule_wrap, fout);
--- 1078,1088 ----
fputs(format->wrap_right, fout);
else if (wrap[j] == PRINT_LINE_WRAP_NEWLINE)
fputs(format->nl_right, fout);
! else if (opt_border == 2 || (col_count > 0 && j < col_count - 1))
fputc(' ', fout);
/* Print column divider, if not the last column */
! if (opt_border != 0 && (col_count > 0 && j < col_count - 1))
{
if (wrap[j + 1] == PRINT_LINE_WRAP_WRAP)
fputs(format->midvrule_wrap, fout);
*************** print_aligned_vertical(const printTableC
*** 1236,1243 ****
if (cont->cells[0] == NULL && cont->opt->start_table &&
cont->opt->stop_table)
{
! if (!opt_tuples_only && cont->opt->default_footer)
! fprintf(fout, _("(No rows)\n"));
return;
}
--- 1237,1254 ----
if (cont->cells[0] == NULL && cont->opt->start_table &&
cont->opt->stop_table)
{
! printTableFooter *footers = footers_with_default(cont);
!
! if (!opt_tuples_only && !cancel_pressed && footers)
! {
! printTableFooter *f;
!
! for (f = footers; f; f = f->next)
! fprintf(fout, "%s\n", f->data);
! }
!
! fputc('\n', fout);
!
return;
}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: bruce@momjian.us, tgl@sss.pgh.pa.us, thom@linux.com
Subject: Re: pgsql: Allow empty target list in SELECT.
In-Reply-To: <20150320122550.GH6317@momjian.us>
References: <E1Vs0Qu-0004bC-6E@gemulon.postgresql.org> <CAA-aLv4mBXOgbSBPhLPa7sqS6PryihFFb_pzQ7Ue07Oci5g3sQ@mail.gmail.com> <27441.1414007839@sss.pgh.pa.us> <CAA-aLv7SjOkt-09Fh8gwh_YQD3B4EcAxzLh7XLyeh9tvKtMwHw@mail.gmail.com> <CAA-aLv47DpdU5HToNQGuw6Zh74BXU3poACW=nH_FK4qmc73N+w@mail.gmail.com> <28123.1414009150@sss.pgh.pa.us> <20150320122550.GH6317@momjian.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox