Thread: Making sure \timing is on

Making sure \timing is on

From
Francisco Reyes
Date:
Is there a way to make certain \timing is on?

I am looking for something simmilar to what one can do with the pager
\pset pager always

Most scripts I am working with (inheritted) don't have \timing in them so I
can put timing on/off as needed. However some scripts already have it. So if
I set \timing before the script and the script calls it again then it gets
turned off.

As I go over all the scripts it will be less of an issue, but I still would
like a way to make sure timing is on, before I run some scripts without
having to first check the script to see if I had put \timing in the script
or not.

Re: Making sure \timing is on

From
Tom Lane
Date:
Francisco Reyes <lists@stringsutils.com> writes:
> Is there a way to make certain \timing is on?

Not that I know of :-(.  There's been discussion of fixing all of psql's
"toggle" commands to offer "\foo on" and "\foo off" variants, which
would be far more scripting-friendly ... but nobody's stepped up to do it.

            regards, tom lane

Re: Making sure \timing is on

From
Francisco Reyes
Date:
Tom Lane writes:

> Not that I know of :-(.  There's been discussion of fixing all of psql's
> "toggle" commands to offer "\foo on" and "\foo off"

What would be a good starting point for someone interesting in looking into
working on that?

Started a job recently as PostgresSQL DBA.. so sooner or later I will want
to start looking at the code. This may be one way to get my feet wet with
the code.


Re: Making sure \timing is on

From
Tom Lane
Date:
Francisco Reyes <lists@stringsutils.com> writes:
> Tom Lane writes:
>> Not that I know of :-(.  There's been discussion of fixing all of psql's
>> "toggle" commands to offer "\foo on" and "\foo off"

> What would be a good starting point for someone interesting in looking into
> working on that?

This'd be a fine starting project IMHO, if you can read/code C at all.
The rubber meets the road in exec_command() in src/bin/psql/command.c
--- look around in that area.  In particular note that ParseVariableBool
in variables.c probably ought to be what you use to interpret the
meaning of the argument.

            regards, tom lane

Re: Making sure \timing is on

From
"Scott Marlowe"
Date:
On Sun, May 11, 2008 at 9:04 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Francisco Reyes <lists@stringsutils.com> writes:
>> Tom Lane writes:
>>> Not that I know of :-(.  There's been discussion of fixing all of psql's
>>> "toggle" commands to offer "\foo on" and "\foo off"
>
>> What would be a good starting point for someone interesting in looking into
>> working on that?
>
> This'd be a fine starting project IMHO, if you can read/code C at all.
> The rubber meets the road in exec_command() in src/bin/psql/command.c
> --- look around in that area.  In particular note that ParseVariableBool
> in variables.c probably ought to be what you use to interpret the
> meaning of the argument.

Is it reasonable behavior to have \timing along toggle and \timing on
/ \timing off be a forced switch?  Just thinking of other scripts
where this isn't a problem and having to update them.

Re: Making sure \timing is on

From
Tom Lane
Date:
"Scott Marlowe" <scott.marlowe@gmail.com> writes:
> Is it reasonable behavior to have \timing along toggle and \timing on
> / \timing off be a forced switch?  Just thinking of other scripts
> where this isn't a problem and having to update them.

The command without an argument should certainly keep the old toggle
behavior, for backwards compatibility.

            regards, tom lane

Re: Making sure \timing is on

From
David Fetter
Date:
On Sun, May 11, 2008 at 11:48:29PM -0400, Tom Lane wrote:
> "Scott Marlowe" <scott.marlowe@gmail.com> writes:
> > Is it reasonable behavior to have \timing along toggle and \timing on
> > / \timing off be a forced switch?  Just thinking of other scripts
> > where this isn't a problem and having to update them.
>
> The command without an argument should certainly keep the old toggle
> behavior, for backwards compatibility.

Attached patch does some of the right thing, but doesn't yet handle
error cases.  How liberal should we be about capitalization, spelling,
etc.?

Cheers,
David.
--
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter@gmail.com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

Attachment

Re: Making sure \timing is on

From
Bruce Momjian
Date:
David Fetter wrote:
> On Sun, May 11, 2008 at 11:48:29PM -0400, Tom Lane wrote:
> > "Scott Marlowe" <scott.marlowe@gmail.com> writes:
> > > Is it reasonable behavior to have \timing along toggle and \timing on
> > > / \timing off be a forced switch?  Just thinking of other scripts
> > > where this isn't a problem and having to update them.
> >
> > The command without an argument should certainly keep the old toggle
> > behavior, for backwards compatibility.
>
> Attached patch does some of the right thing, but doesn't yet handle
> error cases.  How liberal should we be about capitalization, spelling,
> etc.?

Please try ParseVariableBool() in psql/variables.c, and use diff -c.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

Re: Making sure \timing is on

From
Alvaro Herrera
Date:
David Fetter escribió:
> On Sun, May 11, 2008 at 11:48:29PM -0400, Tom Lane wrote:
> > "Scott Marlowe" <scott.marlowe@gmail.com> writes:
> > > Is it reasonable behavior to have \timing along toggle and \timing on
> > > / \timing off be a forced switch?  Just thinking of other scripts
> > > where this isn't a problem and having to update them.
> >
> > The command without an argument should certainly keep the old toggle
> > behavior, for backwards compatibility.
>
> Attached patch does some of the right thing, but doesn't yet handle
> error cases.  How liberal should we be about capitalization, spelling,

Hmm, there's already code for parsing boolean variables in psql, see
ParseVariableBool.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

Re: Making sure \timing is on

From
David Fetter
Date:
On Mon, May 12, 2008 at 05:30:48PM -0400, Bruce Momjian wrote:
> David Fetter wrote:
> > On Sun, May 11, 2008 at 11:48:29PM -0400, Tom Lane wrote:
> > > "Scott Marlowe" <scott.marlowe@gmail.com> writes:
> > > > Is it reasonable behavior to have \timing along toggle and \timing on
> > > > / \timing off be a forced switch?  Just thinking of other scripts
> > > > where this isn't a problem and having to update them.
> > >
> > > The command without an argument should certainly keep the old toggle
> > > behavior, for backwards compatibility.
> >
> > Attached patch does some of the right thing, but doesn't yet handle
> > error cases.  How liberal should we be about capitalization, spelling,
> > etc.?
>
> Please try ParseVariableBool() in psql/variables.c, and use diff -c.

Thanks for the heads-up :)

Second patch attached, this time with some docs.

Cheers,
David.
--
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter@gmail.com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

Attachment

Re: Making sure \timing is on

From
Alvaro Herrera
Date:
David Fetter escribió:

> Thanks for the heads-up :)
>
> Second patch attached, this time with some docs.

Added to July commitfest.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

Re: Making sure \timing is on

From
Tom Lane
Date:
Alvaro Herrera <alvherre@commandprompt.com> writes:
> David Fetter escribi�:
>> Thanks for the heads-up :)
>>
>> Second patch attached, this time with some docs.

> Added to July commitfest.

Surely this is merely proof of concept and not a complete patch.

            regards, tom lane

Re: Making sure \timing is on

From
Alvaro Herrera
Date:
Tom Lane escribió:
> Alvaro Herrera <alvherre@commandprompt.com> writes:
> > David Fetter escribi�:
> >> Thanks for the heads-up :)
> >>
> >> Second patch attached, this time with some docs.
>
> > Added to July commitfest.
>
> Surely this is merely proof of concept and not a complete patch.

David, ya heard da man :-)

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

Re: Making sure \timing is on

From
David Fetter
Date:
On Tue, May 13, 2008 at 10:47:40AM -0400, Alvaro Herrera wrote:
> Tom Lane escribió:
> > Alvaro Herrera <alvherre@commandprompt.com> writes:
> > > David Fetter escribi?:
> > >> Thanks for the heads-up :)
> > >>
> > >> Second patch attached, this time with some docs.
> >
> > > Added to July commitfest.
> >
> > Surely this is merely proof of concept and not a complete patch.
>
> David, ya heard da man :-)

Next patch attached :)

Cheers,
David (free() the malloc()s!)
--
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter@gmail.com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

Re: Making sure \timing is on

From
David Fetter
Date:
On Tue, May 13, 2008 at 08:14:51AM -0700, David Fetter wrote:
> On Tue, May 13, 2008 at 10:47:40AM -0400, Alvaro Herrera wrote:
> > Tom Lane escribió:
> > > Alvaro Herrera <alvherre@commandprompt.com> writes:
> > > > David Fetter escribi?:
> > > >> Thanks for the heads-up :)
> > > >>
> > > >> Second patch attached, this time with some docs.
> > >
> > > > Added to July commitfest.
> > >
> > > Surely this is merely proof of concept and not a complete patch.
> >
> > David, ya heard da man :-)
>
> Next patch attached :)
>
> Cheers,
> David (free() the malloc()s!)

*Sigh*

This time with the patch actually attached :P

Cheers,
David
--
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter@gmail.com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

Attachment

Re: Making sure \timing is on

From
Tom Lane
Date:
David Fetter <david@fetter.org> writes:
>>> Surely this is merely proof of concept and not a complete patch.
>>
>> Next patch attached :)

Uh, my point was that the agreement was to do this to *all* of psql's
toggling backslash commands, not only \timing.

            regards, tom lane

Re: Making sure \timing is on

From
David Fetter
Date:
On Tue, May 13, 2008 at 11:36:57AM -0400, Tom Lane wrote:
> David Fetter <david@fetter.org> writes:
> >>> Surely this is merely proof of concept and not a complete patch.
> >>
> >> Next patch attached :)
>
> Uh, my point was that the agreement was to do this to *all* of
> psql's toggling backslash commands, not only \timing.

Done :)

Cheers,
David.
--
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter@gmail.com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

Attachment

Re: Making sure \timing is on

From
David Fetter
Date:
On Tue, May 13, 2008 at 01:53:33PM -0700, David Fetter wrote:
> On Tue, May 13, 2008 at 11:36:57AM -0400, Tom Lane wrote:
> > David Fetter <david@fetter.org> writes:
> > >>> Surely this is merely proof of concept and not a complete patch.
> > >>
> > >> Next patch attached :)
> >
> > Uh, my point was that the agreement was to do this to *all* of
> > psql's toggling backslash commands, not only \timing.
>
> Done :)

Ugh.  This time with the correct patch attached :P

Cheers,
David (not having much luck with attachments)
--
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter@gmail.com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

Attachment

Re: Making sure \timing is on

From
Tom Lane
Date:
David Fetter <david@fetter.org> writes:
> On Tue, May 13, 2008 at 11:36:57AM -0400, Tom Lane wrote:
>>> Uh, my point was that the agreement was to do this to *all* of
>>> psql's toggling backslash commands, not only \timing.
>>
>> Done :)

Hmm, I thought we had a lot more than three that were like this.
But on looking closer, I guess all the other ones are \pset boolean
options that already behave properly.

Actually, \a and \H are fairly bogus anyway, because they are "toggling"
a setting that has more than two values.  I wonder whether defining the
argument as a boolean is really very sane.  Perhaps it would be better to
take the argument if given as just a regular format setting --- ie,
with an argument, either of these would just be a shorthand for
\pset format.

            regards, tom lane

Re: Making sure \timing is on

From
Alvaro Herrera
Date:
Tom Lane escribió:

> Actually, \a and \H are fairly bogus anyway, because they are "toggling"
> a setting that has more than two values.  I wonder whether defining the
> argument as a boolean is really very sane.  Perhaps it would be better to
> take the argument if given as just a regular format setting --- ie,
> with an argument, either of these would just be a shorthand for
> \pset format.

Agreed -- they are bogus.  However, making "\H aligned" be an alias for
"\pset format aligned" does not look very sane either (is that "html
aligned" or what?)

Seeing how these have been deprecated for a very long while, perhaps the
thing to do is leave their behavior alone and throw a warning when they
are used; in a couple more releases, remove them.  However this isn't
very sane either, because we'd break scripts that are using \H for no
good reason.

Another thing we could do is keep them as "toggles", but instead of
aligned/HTML and aligned/unaligned, make them remember the state that
was set at the time they were called, and toggle between HTML (or
aligned) and the last state.

... except that since aligned is the default mode, \a should not toggle
between last state and aligned, but rather between last state and
unaligned.  Which makes it a misnomer.

Or maybe the thing to do is leave them damn well alone and just fix
\timing.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.