Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

why is the result right aligned.....

173 views
Skip to first unread message

Luuk

unread,
Apr 22, 2012, 3:26:46 AM4/22/12
to
I am creating a script (bash) on linux, and the result does not need to
have column-names..

Why is the text column right aligned, if i do this:

~> mysql test -Ne "select * from test1 limit 2"
+---+---+------------------------------------------+
| 1 | 1 | YY |
| 2 | 2 | YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY |
+---+---+------------------------------------------+

If i leave out the '-N' the result is aligned OK:

~> mysql test -e "select * from test1 limit 2"
+----+---------+------------------------------------------+
| id | USER_ID | TEXT |
+----+---------+------------------------------------------+
| 1 | 1 | YY |
| 2 | 2 | YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY |
+----+---------+------------------------------------------+

Does anyone have a good suggestion on how to get output to be
left-aligned (and without column-names)?

--
Luuk
Mysql version 5.5


Tony Mountifield

unread,
Apr 22, 2012, 10:07:06 AM4/22/12
to
How about:

~> mysql test -e "select * from test1 limit 2" | tail +3
+----+---------+------------------------------------------+
| 1 | 1 | YY |
| 2 | 2 | YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY |
+----+---------+------------------------------------------+

But I don't know why the alignment is different with -N

Cheers
Tony
--
Tony Mountifield
Work: to...@softins.co.uk - http://www.softins.co.uk
Play: to...@mountifield.org - http://tony.mountifield.org

Luuk

unread,
Apr 22, 2012, 12:01:48 PM4/22/12
to Tony Mountifield
hmm, than i could do this too:
~> mysql test -Ne "select * from test1 limit 2" | sed -e 's/\(
*\)\([A-Z]*\)/\2\1/'
1 1 YY
2 2 YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY

to get rid of the simple character lines... ;)

Thomas 'PointedEars' Lahn

unread,
Apr 25, 2012, 9:37:23 PM4/25/12
to
Tony Mountifield wrote:
Is it really not obvious enough?

$ mysql --help | grep -e -N
-N, --skip-column-names

The column in the *output* is only that wide, and the number is aligned
right, because of the column name and the numeric field type. Where there
is no column name to put out, there is no need to literally waste space,
and all the numbers here are only one digit wide. So the column output is
(without padding and border) only one character wide.

--
PointedEars

Please do not Cc: me. / Bitte keine Kopien per E-Mail.

"Álvaro G. Vicario"

unread,
Apr 26, 2012, 3:55:28 AM4/26/12
to
El 26/04/2012 3:37, Thomas 'PointedEars' Lahn escribió/wrote:
>>> Why is the text column right aligned, if i do this:
>>>
>>> ~> mysql test -Ne "select * from test1 limit 2"
>>> +---+---+------------------------------------------+
>>> | 1 | 1 | YY |
>>> | 2 | 2 | YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY |
>>> +---+---+------------------------------------------+
>>>
>>> If i leave out the '-N' the result is aligned OK:
>>>
>>> ~> mysql test -e "select * from test1 limit 2"
>>> +----+---------+------------------------------------------+
>>> | id | USER_ID | TEXT |
>>> +----+---------+------------------------------------------+
>>> | 1 | 1 | YY |
>>> | 2 | 2 | YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY |
>>> +----+---------+------------------------------------------+

> The column in the *output* is only that wide, and the number is aligned
> right, because of the column name and the numeric field type. Where there
> is no column name to put out, there is no need to literally waste space,
> and all the numbers here are only one digit wide. So the column output is
> (without padding and border) only one character wide.

I suspect the OP is actually worried about the right aligned "YY" string.



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--

The Natural Philosopher

unread,
Apr 26, 2012, 7:25:03 AM4/26/12
to
Álvaro G. Vicario wrote:
> El 26/04/2012 3:37, Thomas 'PointedEars' Lahn escribió/wrote:
>>>> Why is the text column right aligned, if i do this:
>>>>
>>>> ~> mysql test -Ne "select * from test1 limit 2"
>>>> +---+---+------------------------------------------+
>>>> | 1 | 1 | YY |
>>>> | 2 | 2 | YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY |
>>>> +---+---+------------------------------------------+
>>>>
>>>> If i leave out the '-N' the result is aligned OK:
>>>>
>>>> ~> mysql test -e "select * from test1 limit 2"
>>>> +----+---------+------------------------------------------+
>>>> | id | USER_ID | TEXT |
>>>> +----+---------+------------------------------------------+
>>>> | 1 | 1 | YY |
>>>> | 2 | 2 | YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY |
>>>> +----+---------+------------------------------------------+
>
>> The column in the *output* is only that wide, and the number is aligned
>> right, because of the column name and the numeric field type. Where
>> there
>> is no column name to put out, there is no need to literally waste space,
>> and all the numbers here are only one digit wide. So the column
>> output is
>> (without padding and border) only one character wide.
>
> I suspect the OP is actually worried about the right aligned "YY" string.
>
>
well perhaps when you skip column names it assumes numeric results.

>


--
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.

Luuk

unread,
Apr 26, 2012, 2:42:36 PM4/26/12
to The Natural Philosopher
i suspect to too, ...... ;)

>>
> well perhaps when you skip column names it assumes numeric results.

No, it cannot, because MySQL is smart enough, ( and if MySQL is not,
than their developers are!) to understand that 'YY' can never be a
number...

Lennart Jonsson

unread,
Apr 27, 2012, 1:35:54 PM4/27/12
to
On 2012-04-26 20:42, Luuk wrote:
> On 26-04-2012 13:25, The Natural Philosopher wrote:
[...]
>> well perhaps when you skip column names it assumes numeric results.
>
> No, it cannot, because MySQL is smart enough, ( and if MySQL is not,
> than their developers are!) to understand that 'YY' can never be a
> number...
>

Hell no! 'YY' is the identity element of addition and must therefore be
a number:

mysql> select 'YY' + 3;
+----------+
| 'YY' + 3 |
+----------+
| 3 |
+----------+
1 row in set, 1 warning (0.01 sec)


/Lennart

Luuk

unread,
Apr 27, 2012, 2:22:20 PM4/27/12
to Lennart Jonsson
OK, i should rephrase my question.....

Why is a column considered numeric if the column titles are not shown...

~> mysql -Ne "select 'YY' + 3 as 'X' UNION select '1E3' UNION select
'1E3' + 4 UNION select 'X';"
+------+
| 3 |
| 1E3 |
| 1004 |
| X |
+------+
~> mysql -e "select 'YY' + 3 as 'X' UNION select '1E3' UNION select
'1E3' + 4 UNION select 'X';"
+------+
| X |
+------+
| 3 |
| 1E3 |
| 1004 |
| X |
+------+

--
Luuk

Luuk

unread,
Apr 27, 2012, 2:56:15 PM4/27/12
to
http://bugs.mysql.com/bug.php?id=65137

~> mysql -e "select 'XX' UNION select 'XXXXXXXX'"
+----------+
| XX |
+----------+
| XX |
| XXXXXXXX |
+----------+
~> mysql -Ne "select 'XX' UNION select 'XXXXXXXX'"
+----------+
| XX |
| XXXXXXXX |
+----------+
~> mysql -Ne "select 1,'XX' UNION select 2,'XXXXXXXX'"
+---+----------+
| 1 | XX |
| 2 | XXXXXXXX |
+---+----------+

The last result is unexpected. The 'XX' should be left-aligned.

--
Luuk

Thomas 'PointedEars' Lahn

unread,
Apr 28, 2012, 2:09:16 AM4/28/12
to
Álvaro G. Vicario wrote:

> El 26/04/2012 3:37, Thomas 'PointedEars' Lahn escribió/wrote:
>>>> Why is the text column right aligned, if i do this:
>>>>
>>>> ~> mysql test -Ne "select * from test1 limit 2"
>>>> +---+---+------------------------------------------+
>>>> | 1 | 1 | YY |
>>>> | 2 | 2 | YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY |
>>>> +---+---+------------------------------------------+
>>>>
>>>> If i leave out the '-N' the result is aligned OK:
>>>>
>>>> ~> mysql test -e "select * from test1 limit 2"
>>>> +----+---------+------------------------------------------+
>>>> | id | USER_ID | TEXT |
>>>> +----+---------+------------------------------------------+
>>>> | 1 | 1 | YY |
>>>> | 2 | 2 | YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY |
>>>> +----+---------+------------------------------------------+
>> […]
>> The column in the *output* is only that wide, and the number is aligned
>> right, because of the column name and the numeric field type. Where
>> there is no column name to put out, there is no need to literally waste
>> space, and all the numbers here are only one digit wide. So the column-
>> output is (without padding and border) only one character wide.
>
> I suspect the OP is actually worried about the right aligned "YY" string.

Ahh, right[tm]. That looks like a bug to me.
0 new messages