Re: psql \sf doesn't show it's SQL when ECHO_HIDDEN is on

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql \sf doesn't show it's SQL when ECHO_HIDDEN is on
Date: 2014-11-21 20:20:12
Message-ID: 546F9E7C.5070209@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 11/21/2014 02:44 PM, Tom Lane wrote:
> Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>> Well, now we get things like this:
>> ERROR: more than one function named "abc"
>> LINE 1: SELECT 'abc'::pg_catalog.regproc::pg_catalog.oid
>> whereas minimal_error_message suppressed the second line. If we want to
>> preserve that older behaviour we'll have to abandon use of PSQLexec. But
>> it's not so complex that that would be a huge issue.
> Yeah, the reason why we wrote that code to begin with was that there
> were a bunch of user-facing error cases that would be reported by
> regproc_in/regprocedure_in, and we didn't want to clutter those error
> reports with the underlying queries.
>
> I'm not sure how I feel about changing this. Making these queries subject
> to ECHO_HIDDEN seems like we're exposing them to users to some extent
> anyway, and maybe it's not worth dozens of lines of code (and duplicating
> large parts of PSQLexec) to avoid the extra output. On the other hand
> this output doesn't seem very nice from a fit-and-finish standpoint.

Here's a patch that I think does what you want. I didn't have to borrow
too much code from PSQLexec(). Sample session:

andrew=# \sf abc
ERROR: more than one function named "abc"
andrew=# \sf blurfl
ERROR: function "blurfl" does not exist
andrew=# \sf abc()
CREATE OR REPLACE FUNCTION public.abc()
RETURNS integer
LANGUAGE sql
AS $function$ select 1$function$
andrew=# \set ECHO_HIDDEN 1
andrew=# \sf abc()
********* QUERY **********
SELECT 'abc()'::pg_catalog.regprocedure::pg_catalog.oid
**************************

********* QUERY **********
SELECT pg_catalog.pg_get_functiondef(16385)
**************************

CREATE OR REPLACE FUNCTION public.abc()
RETURNS integer
LANGUAGE sql
AS $function$ select 1$function$
andrew=# \sf abc
********* QUERY **********
SELECT 'abc'::pg_catalog.regproc::pg_catalog.oid
**************************

ERROR: more than one function named "abc"
andrew=#

cheers

andrew

Attachment Content-Type Size
psql-sf-ef-echo_hidden-fix.patch text/x-diff 2.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2014-11-21 20:38:41 Re: INSERT ... ON CONFLICT {UPDATE | IGNORE}
Previous Message Peter Geoghegan 2014-11-21 20:14:53 Re: RLS with check option - surprised design