Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Patches > Re: [NOVICE] en...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 21 Topic 3696 of 3917
Post > Topic >>

Re: [NOVICE] encoding problems

by bruce@[EMAIL PROTECTED] (Bruce Momjian) May 7, 2008 at 11:47 AM

--ELM1210175270-27620-1_
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="US-ASCII"

Cliff Nieuwenhuis wrote:
> On Tuesday 11 March 2008 11:41:35 Tom Lane wrote:
> > Cliff Nieuwenhuis <cliff@[EMAIL PROTECTED]
> 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@[EMAIL PROTECTED]
>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

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

--ELM1210175270-27620-1_
Content-Transfer-Encoding: 7bit
Content-Type: text/x-diff
Content-Disposition: inline; filename="/pgpatches/psql_tab"

Index: src/bin/psql/mbprint.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/mbprint.c,v
retrieving revision 1.30
diff -c -c -r1.30 mbprint.c
*** src/bin/psql/mbprint.c	16 Apr 2008 18:18:00 -0000	1.30
--- src/bin/psql/mbprint.c	7 May 2008 15:18:25 -0000
***************
*** 315,320 ****
--- 315,330 ----
  				linewidth += 2;
  				ptr += 2;
  			}
+ 			else if (*pwcs == '\t')		/* Tab */
+ 			{
+ 				strcpy((char *) ptr, "\t");
+ 				/*
+ 				 *	We don't know what tab stop we are on, so assuming 8-space
+ 				 *	tabs, the average width of a tab is 4.
+ 				 */
+ 				linewidth += 4;
+ 				ptr += 1;
+ 			}
  			else if (w < 0)		/* Other control char */
  			{
  				sprintf((char *) ptr, "\\x%02X", *pwcs);

--ELM1210175270-27620-1_
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0


-- 
Sent via pgsql-patches mailing list (pgsql-patches@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches

--ELM1210175270-27620-1_--
 




 21 Posts in Topic:
Re: [NOVICE] encoding problems
bruce@[EMAIL PROTECTED]   2008-05-07 11:47:50 
Re: [NOVICE] encoding problems
tgl@[EMAIL PROTECTED] (T  2008-05-07 12:06:40 
Re: [NOVICE] encoding problems
bruce@[EMAIL PROTECTED]   2008-05-07 13:20:05 
Re: [NOVICE] encoding problems
alvherre@[EMAIL PROTECTED  2008-05-07 13:37:02 
Re: [NOVICE] encoding problems
bruce@[EMAIL PROTECTED]   2008-05-07 13:46:11 
Re: [NOVICE] encoding problems
alvherre@[EMAIL PROTECTED  2008-05-07 14:15:14 
Re: [NOVICE] encoding problems
bruce@[EMAIL PROTECTED]   2008-05-07 14:24:09 
Re: [NOVICE] encoding problems
alvherre@[EMAIL PROTECTED  2008-05-07 14:44:29 
Re: [NOVICE] encoding problems
bruce@[EMAIL PROTECTED]   2008-05-07 14:46:28 
Re: [NOVICE] encoding problems
bruce@[EMAIL PROTECTED]   2008-05-07 16:32:43 
Re: [NOVICE] encoding problems
bruce@[EMAIL PROTECTED]   2008-05-08 15:11:59 
Re: [NOVICE] encoding problems
guillaume.smet@[EMAIL PRO  2008-05-09 04:37:26 
Re: [NOVICE] encoding problems
bruce@[EMAIL PROTECTED]   2008-05-08 22:38:30 
Re: [NOVICE] encoding problems
alvherre@[EMAIL PROTECTED  2008-05-09 08:38:01 
Re: [NOVICE] encoding problems
guillaume.smet@[EMAIL PRO  2008-05-09 04:47:20 
Re: [NOVICE] encoding problems
bruce@[EMAIL PROTECTED]   2008-05-08 23:26:21 
Re: [HACKERS] [NOVICE] encoding problems
tgl@[EMAIL PROTECTED] (T  2008-05-09 10:39:33 
Re: [HACKERS] [NOVICE] encoding problems
bruce@[EMAIL PROTECTED]   2008-05-09 11:40:03 
Re: [HACKERS] [NOVICE] encoding problems
tgl@[EMAIL PROTECTED] (T  2008-05-09 11:59:33 
Re: [NOVICE] encoding problems
cliff@[EMAIL PROTECTED]   2008-05-10 09:19:52 
Re: [NOVICE] encoding problems
bruce@[EMAIL PROTECTED]   2008-06-30 15:52:08 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Thu Jul 24 6:56:31 CDT 2008.