Обсуждение: Spacing in output

Поиск
Список
Период
Сортировка

Spacing in output

От
Jerome Lyles
Дата:
I have a small training database: sql_tutorial.  It works fine but the spacing
between the output lines is too much.  This is the way it looks when I copy
and paste from the Konsole to this email:

sql_tutorial=> SELECT prod_name FROM Products;
                                            prod_name

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 8 inch teddy bear
 12 inch teddy bear
 18 inch teddy bear


This is the way it looks on the Konsole:

 sql_tutorial=> SELECT prod_name FROM Products;

                                            prod_name
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
------------------
 8 inch teddy bear


 12 inch teddy bear


 18 inch teddy bear

How can I change the Konsole output to look like the first example?
Thanks,
Jerome
    

Re: Spacing in output

От
Thomas F.O'Connell
Дата:
The spacing in Konsole is directly related to the wrapping that it's
doing based on the size of the prod_name field (I.e., length in terms
of characters).

You can alter the format settings of psql. See:

http://www.postgresql.org/docs/7.4/static/app-psql.html

-tfo

On Sep 14, 2004, at 4:05 PM, Jerome Lyles wrote:

> I have a small training database: sql_tutorial.  It works fine but the
> spacing
> between the output lines is too much.  This is the way it looks when I
> copy
> and paste from the Konsole to this email:
>
> sql_tutorial=> SELECT prod_name FROM Products;
>                                             prod_name
> -----------------------------------------------------------------------
> -----------------------------------------------------------------------
> -----------------------------------------------------------------------
> --------------------------------------------
>  8 inch teddy bear
>  12 inch teddy bear
>  18 inch teddy bear
>
>
> This is the way it looks on the Konsole:
>
>  sql_tutorial=> SELECT prod_name FROM Products;
>
>                                             prod_name
> -----------------------------------------------------------------------
> ---------------
> -----------------------------------------------------------------------
> ---------------
> -----------------------------------------------------------------------
> ---------------
> ------------------
>  8 inch teddy bear
>
>
>  12 inch teddy bear
>
>
>  18 inch teddy bear
>
> How can I change the Konsole output to look like the first example?
> Thanks,
> Jerome
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 8: explain analyze is your friend


Re: Spacing in output

От
Duane Lee - EGOVX
Дата:

What is the field size of prod_name?  You could use SUBSTR(prod_name,1,xx) where xx is the max number of characters you want to see.

Duane

-----Original Message-----
From: Jerome Lyles [mailto:susemail@hawaii.rr.com]
Sent: Tuesday, September 14, 2004 2:06 PM
To: pgsql-general@postgresql.org
Subject: [GENERAL] Spacing in output

I have a small training database: sql_tutorial.  It works fine but the spacing
between the output lines is too much.  This is the way it looks when I copy
and paste from the Konsole to this email:

sql_tutorial=> SELECT prod_name FROM Products;
                                            prod_name
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 8 inch teddy bear
 12 inch teddy bear
 18 inch teddy bear 

This is the way it looks on the Konsole:

 sql_tutorial=> SELECT prod_name FROM Products;

                                            prod_name
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
------------------
 8 inch teddy bear

 12 inch teddy bear

 18 inch teddy bear

How can I change the Konsole output to look like the first example?
Thanks,
Jerome                                                                                                                    

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Re: Spacing in output

От
David Fetter
Дата:
On Tue, Sep 14, 2004 at 11:05:46AM -1000, Jerome Lyles wrote:
> I have a small training database: sql_tutorial.  It works fine but the spacing
> between the output lines is too much.  This is the way it looks when I copy
> and paste from the Konsole to this email:
>
> sql_tutorial=> SELECT prod_name FROM Products;

Is prod_name a char(n) for some large n?

Cheers,
D
>                                             prod_name
>
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>  8 inch teddy bear
>  12 inch teddy bear
>  18 inch teddy bear
>
>
> This is the way it looks on the Konsole:
>
>  sql_tutorial=> SELECT prod_name FROM Products;
>
>                                             prod_name
> --------------------------------------------------------------------------------------
> --------------------------------------------------------------------------------------
> --------------------------------------------------------------------------------------
> ------------------
>  8 inch teddy bear
>
>
>  12 inch teddy bear
>
>
>  18 inch teddy bear
>
> How can I change the Konsole output to look like the first example?
> Thanks,
> Jerome
      
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend

--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!

Re: Spacing in output

От
Jerome Lyles
Дата:
On Tuesday 14 September 2004 11:15 am, you wrote:
> What is the field size of prod_name?  You could use SUBSTR(prod_name,1,xx)
> where xx is the max number of characters you want to see.
>
> Duane
fieldsize: 255.  I tried to use SUBSTR:

sql_tutorial=> SUBSTR(prod_name,1,45; SELECT prod_name FROM Products;
sql_tutorial(>
sql_tutorial(>
sql_tutorial(> SELECT prod_name FROM Products;
sql_tutorial(> SUBSTR(prod_name,1,45;

but I have the syntax wrong.  What does '(>' instead of '=>' mean?
Thanks,
Jerome

Re: Spacing in output

От
Duane Lee - EGOVX
Дата:

Do this:

SELECT SUBSTR(prod_name,1,45) from Products;

Duane

-----Original Message-----
From: Jerome Lyles [mailto:susemail@hawaii.rr.com]
Sent: Tuesday, September 14, 2004 4:22 PM
To: pgsql-general@postgresql.org
Subject: Re: [GENERAL] Spacing in output

On Tuesday 14 September 2004 11:15 am, you wrote:
> What is the field size of prod_name?  You could use SUBSTR(prod_name,1,xx)
> where xx is the max number of characters you want to see.
>
> Duane
fieldsize: 255.  I tried to use SUBSTR:

sql_tutorial=> SUBSTR(prod_name,1,45; SELECT prod_name FROM Products;
sql_tutorial(>
sql_tutorial(>
sql_tutorial(> SELECT prod_name FROM Products;
sql_tutorial(> SUBSTR(prod_name,1,45;

but I have the syntax wrong.  What does '(>' instead of '=>' mean?
Thanks,
Jerome

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Re: Spacing in output

От
Martijn van Oosterhout
Дата:
On Tue, Sep 14, 2004 at 01:21:48PM -1000, Jerome Lyles wrote:
> On Tuesday 14 September 2004 11:15 am, you wrote:
> > What is the field size of prod_name?  You could use SUBSTR(prod_name,1,xx)
> > where xx is the max number of characters you want to see.
> >
> > Duane
> fieldsize: 255.  I tried to use SUBSTR:
>
> sql_tutorial=> SUBSTR(prod_name,1,45; SELECT prod_name FROM Products;
> sql_tutorial(>
> sql_tutorial(>
> sql_tutorial(> SELECT prod_name FROM Products;
> sql_tutorial(> SUBSTR(prod_name,1,45;
>
> but I have the syntax wrong.  What does '(>' instead of '=>' mean?

That means you havn't closed the opening bracket on the first line.
Every open bracket must be matched by a closing one...

--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Вложения

Re: Spacing in output

От
Jerome Lyles
Дата:
On Tuesday 14 September 2004 11:27 am, David Fetter wrote:
> On Tue, Sep 14, 2004 at 11:05:46AM -1000, Jerome Lyles wrote:
> > I have a small training database: sql_tutorial.  It works fine but the
> > spacing between the output lines is too much.  This is the way it looks
> > when I copy and paste from the Konsole to this email:
> >
> > sql_tutorial=> SELECT prod_name FROM Products;
>
> Is prod_name a char(n) for some large n?
>
> Cheers,
> D
char(255)
Jerome

Re: Spacing in output

От
David Fetter
Дата:
On Tue, Sep 14, 2004 at 06:37:40PM -1000, Jerome Lyles wrote:
> On Tuesday 14 September 2004 11:27 am, David Fetter wrote:
> > On Tue, Sep 14, 2004 at 11:05:46AM -1000, Jerome Lyles wrote:
> > > I have a small training database: sql_tutorial.  It works fine
> > > but the spacing between the output lines is too much.  This is
> > > the way it looks when I copy and paste from the Konsole to this
> > > email:

> > > sql_tutorial=> SELECT prod_name FROM Products;
> >
> > Is prod_name a char(n) for some large n?
> >
> > Cheers,
> > D
> char(255)

Well, Don't Do That, Then.  TEXT is a great type for storing text.
VARCHAR(n) is a TEXT with a maximum length constraint, and CHAR(n)
(fixed length) is pretty nearly obsolete.

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!

Re: Spacing in output

От
Jerome Lyles
Дата:
On Wednesday 15 September 2004 05:24 am, David Fetter wrote:
> On Tue, Sep 14, 2004 at 06:37:40PM -1000, Jerome Lyles wrote:
> > On Tuesday 14 September 2004 11:27 am, David Fetter wrote:
> > > On Tue, Sep 14, 2004 at 11:05:46AM -1000, Jerome Lyles wrote:
> > > > I have a small training database: sql_tutorial.  It works fine
> > > > but the spacing between the output lines is too much.  This is
> > > > the way it looks when I copy and paste from the Konsole to this
> > > > email:
> > > >
> > > > sql_tutorial=> SELECT prod_name FROM Products;
> > >
> > > Is prod_name a char(n) for some large n?
> > >
> > > Cheers,
> > > D
> >
> > char(255)
>
> Well, Don't Do That, Then.  TEXT is a great type for storing text.
> VARCHAR(n) is a TEXT with a maximum length constraint, and CHAR(n)
> (fixed length) is pretty nearly obsolete.
>
> Cheers,
> D
This is amazing.  Im using a book called 'Teach Yourself SQL in 10 minutes'
with a 2004 copyright and this is the second example of obsolete TEXT type
used in the examples so far.
Jerome

Re: Spacing in output

От
Jerome Lyles
Дата:
On Tuesday 14 September 2004 01:31 pm, Duane Lee - EGOVX wrote:
> Do this:
>
>
> SELECT SUBSTR(prod_name,1,45) from Products;
>
>
> Duane
I did:

sql_tutorial=> SELECT SUBSTR(prod_name,1,45) from Products;
       substr
---------------------
 8 inch teddy bear
 12 inch teddy bear
 18 inch teddy bear
 Fish bean bag toy
 Bird bean bag toy
 Rabbit bean bag toy
 Raggedy Ann
 King doll
 Queen doll
(9 rows)

Thanks,
Jerome

Re: Spacing in output

От
"Rolf Østvik"
Дата:
susemail@hawaii.rr.com (Jerome Lyles) wrote in
news:200409141105.46091.susemail@hawaii.rr.com:

> I have a small training database: sql_tutorial.  It works fine but the
spacing
> between the output lines is too much.  This is the way it looks when I
copy
> and paste from the Konsole to this email:


the simplest is
SELECT prod_name::text FROM products;

(will cast the char(255) column to text and in the process removes all
trailing spaces.)

or use trim function to remove trailing spaces.

--
Rolf