Re: [NOVICE] encoding problems

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Cliff Nieuwenhuis <cliff(at)nieusite(dot)com>
Cc: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [NOVICE] encoding problems
Date: 2008-05-07 15:47:50
Message-ID: 200805071547.m47Flom06319@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-novice pgsql-patches

Cliff Nieuwenhuis wrote:
> On Tuesday 11 March 2008 11:41:35 Tom Lane wrote:
> > Cliff Nieuwenhuis <cliff(at)nieusite(dot)com> writes:
> > > I'm not sure how to ask this question. I have written a function, and
> > > with PostgreSQL 8.0.13 I can do a "\df+" and see something like this
> > > under Source Code:
> > > DECLARE
> > > result text;
> > > ...
> > >
> > > If I create the same function on my computer running PostgreSQL 8.3.0 and
> > > try the \df+ then the Source Code shows:
> > >
> > > \x09DECLARE
> > > \x09\x09result text;
> > > ...
> >
> > That's not an encoding problem, that's an intentional behavioral change
> > in the way that psql formats strings for display.
> >
> > I guess it's a bit annoying if you were hoping that tabs would be useful
> > for pretty-printing purposes. Should we reconsider what's done with a
> > tab in mbprint.c?
> >
> > regards, tom lane
>
> My vote would be to go back to the old way, or at least have that as an option
> of some sort. I use command-line psql all the time -- to me, psql offers the
> same advantages as using a command-line interface for other work. I find the
> extra characters really get in the way.

Yes, I think our psql display of tabs needs improving too. Our current
behavior is to output tab as 0x09:

test=> SELECT E'\011';
?column?
----------
\x09
(1 row)

test=> CREATE FUNCTION xx() RETURNS text AS E'
test'> SELECT ''a''::text
test'> WHERE 1 = 1'
test-> LANGUAGE SQL;
CREATE FUNCTION

test=> SELECT prosrc FROM pg_proc WHERE proname = 'xx';
prosrc
---------------------

SELECT\x09'a'::text
WHERE\x091 = 1
(1 row)

test=> \x
Expanded display is on.

test=> \df+ xx
List of functions
-[ RECORD 1 ]-------+--------------------
Schema | public
Name | xx
Result data type | text
Argument data types |
Volatility | volatile
Owner | postgres
Language | sql
Source code |
: SELECT\x09'a'::text
: WHERE\x091 = 1
Description |

I have implemented the following patch which outputs tab as a tab. It
also assumes a tab has a width of 4, which is its average width:

test=> SELECT E'\011';
?column?
----------

(1 row)

test=> SELECT prosrc FROM pg_proc WHERE proname = 'xx';
prosrc
---------------------

SELECT 'a'::text
WHERE 1 = 1
(1 row)

test=> \x
Expanded display is on.

test=> \df+ xx
List of functions
-[ RECORD 1 ]-------+--------------------
Schema | public
Name | xx
Result data type | text
Argument data types |
Volatility | volatile
Owner | postgres
Language | sql
Source code |
: SELECT 'a'::text
: WHERE 1 = 1
Description |

The only downside I see for this patch is that we are never sure of the
display width of tab because we don't know what tab stop we are at.
With '\x09' we knew exactly how wide it was.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

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

Attachment Content-Type Size
/pgpatches/psql_tab text/x-diff 770 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2008-05-07 15:50:44 Re: Posting to hackers and patches lists
Previous Message Alex Hunsaker 2008-05-07 15:37:42 Re: Posting to hackers and patches lists

Browse pgsql-novice by date

  From Date Subject
Next Message Don Mies (NIM) 2008-05-07 15:52:27 Disadvantages to using "text"
Previous Message Guillaume Smet 2008-05-07 09:30:16 Re: [NOVICE] encoding problems

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2008-05-07 15:50:44 Re: Posting to hackers and patches lists
Previous Message Alex Hunsaker 2008-05-07 15:37:42 Re: Posting to hackers and patches lists