Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Patches

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-07-2008, 06:21 PM
Bruce Momjian
 
Posts: n/a
Default Re: [NOVICE] encoding problems

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

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


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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-07-2008, 06:21 PM
Tom Lane
 
Posts: n/a
Default Re: [NOVICE] encoding problems

Bruce Momjian <bruce@momjian.us> writes:
> 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:


That pretty much completely sucks; it will undo all the hard work we've
put into nice formatting of the output, because seven times out of eight
this assumption is wrong.

An actually acceptable solution would involve emitting the correct
number of spaces depending on how much we've put out so far.

regards, tom lane

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-07-2008, 06:21 PM
Bruce Momjian
 
Posts: n/a
Default Re: [NOVICE] encoding problems

Tom Lane wrote:
> Bruce Momjian <bruce@momjian.us> writes:
> > 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:

>
> That pretty much completely sucks; it will undo all the hard work we've
> put into nice formatting of the output, because seven times out of eight
> this assumption is wrong.
>
> An actually acceptable solution would involve emitting the correct
> number of spaces depending on how much we've put out so far.


Even if we knew the column position at output time, when we are doing
aligned column width computations, we don't know the width of the
previous columns so we would have no way to know how far the tab would
extend in the current column.

The only other idea I have is to output four spaces rather than '\x09'
for a tab.

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

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

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-07-2008, 06:21 PM
Alvaro Herrera
 
Posts: n/a
Default Re: [NOVICE] encoding problems

Bruce Momjian wrote:

> Even if we knew the column position at output time, when we are doing
> aligned column width computations, we don't know the width of the
> previous columns so we would have no way to know how far the tab would
> extend in the current column.


If you start counting every line from the start of the current column,
it will align correctly regardless of the previous columns.

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

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-07-2008, 06:21 PM
Bruce Momjian
 
Posts: n/a
Default Re: [NOVICE] encoding problems

Alvaro Herrera wrote:
> Bruce Momjian wrote:
>
> > Even if we knew the column position at output time, when we are doing
> > aligned column width computations, we don't know the width of the
> > previous columns so we would have no way to know how far the tab would
> > extend in the current column.

>
> If you start counting every line from the start of the current column,
> it will align correctly regardless of the previous columns.


At this stage you don't know the width of previous columns because you
don't know if a very wide value is coming in a later row, so there is no
way to output the width of the cell with a tab you are looking at now.

Unless I am misunderstanding you.

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

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

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 05-10-2008, 02:06 PM
Alvaro Herrera
 
Posts: n/a
Default Re: [NOVICE] encoding problems

Bruce Momjian wrote:
> Alvaro Herrera wrote:


> > If you start counting every line from the start of the current column,
> > it will align correctly regardless of the previous columns.

>
> At this stage you don't know the width of previous columns because you
> don't know if a very wide value is coming in a later row, so there is no
> way to output the width of the cell with a tab you are looking at now.
>
> Unless I am misunderstanding you.


Surely psql computes the width of all cells before printing anything.

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

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 05-10-2008, 02:06 PM
Bruce Momjian
 
Posts: n/a
Default Re: [NOVICE] encoding problems

Alvaro Herrera wrote:
> Bruce Momjian wrote:
> > Alvaro Herrera wrote:

>
> > > If you start counting every line from the start of the current column,
> > > it will align correctly regardless of the previous columns.

> >
> > At this stage you don't know the width of previous columns because you
> > don't know if a very wide value is coming in a later row, so there is no
> > way to output the width of the cell with a tab you are looking at now.
> >
> > Unless I am misunderstanding you.

>
> Surely psql computes the width of all cells before printing anything.


It does, but if you have a value that has a tab, how do you know what
tab stop you are on because you don't know the final width of the
previous columns at that time, so there is no way to know the width of
that cell.

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

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

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 05-10-2008, 02:06 PM
Alvaro Herrera
 
Posts: n/a
Default Re: [NOVICE] encoding problems

Bruce Momjian wrote:
> Alvaro Herrera wrote:


> > Surely psql computes the width of all cells before printing anything.

>
> It does, but if you have a value that has a tab, how do you know what
> tab stop you are on because you don't know the final width of the
> previous columns at that time, so there is no way to know the width of
> that cell.


My point is that you don't need to align the tabstops with the start of
the line, but with the start of the _column_. So the width of the
previous column doesn't matter.

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

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 05-10-2008, 02:06 PM
Bruce Momjian
 
Posts: n/a
Default Re: [NOVICE] encoding problems

Alvaro Herrera wrote:
> Bruce Momjian wrote:
> > Alvaro Herrera wrote:

>
> > > Surely psql computes the width of all cells before printing anything.

> >
> > It does, but if you have a value that has a tab, how do you know what
> > tab stop you are on because you don't know the final width of the
> > previous columns at that time, so there is no way to know the width of
> > that cell.

>
> My point is that you don't need to align the tabstops with the start of
> the line, but with the start of the _column_. So the width of the
> previous column doesn't matter.


OK, so I am not really using tabs in the output, but outputting the
proper number of spaces to make it look like a tab? That works. Let me
try it.

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

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

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 05-10-2008, 02:06 PM
Bruce Momjian
 
Posts: n/a
Default Re: [NOVICE] encoding problems

Alvaro Herrera wrote:
> Bruce Momjian wrote:
> > Alvaro Herrera wrote:

>
> > > Surely psql computes the width of all cells before printing anything.

> >
> > It does, but if you have a value that has a tab, how do you know what
> > tab stop you are on because you don't know the final width of the
> > previous columns at that time, so there is no way to know the width of
> > that cell.

>
> My point is that you don't need to align the tabstops with the start of
> the line, but with the start of the _column_. So the width of the
> previous column doesn't matter.


Alvaro, using spaces instead of the terminal hard tabs was a very good
idea. The output is now:

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 |


Patch attached. It substitutes spaces for the tab.

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

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


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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:28 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145