vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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 |
| |||
| 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 |
| |||
| 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 |
| |||
| 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 |
| |||
| 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 |
| |||
| 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 |
| |||
| 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 |
| |||
| 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 |
| ||||
| 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 |