pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Looks are important
7+ messages / 4 participants
[nested] [flat]

* Looks are important
@ 2003-11-12 22:12  George Weaver <georgew1@mts.net>
  0 siblings, 2 replies; 7+ messages in thread

From: George Weaver @ 2003-11-12 22:12 UTC (permalink / raw)
  To: pgsql-sql

Hi Everyone,

I am trying to concatenate two fields through a query:

SELECT RPAD(no,30,' ') || tableb.kind FROM tablea 
WHERE tablea.kind = tableb.kind

The result gives (for example):

4595448                       Green
5966                          Yellow
106-60033                     Green
15-94-387                     Red
217-991173                    Blue

What I would like to have is better alignment:

4595448                     Green
5966                          Yellow
106-60033                  Green
15-94-387                   Red
217-991173                 Blue

Is there some kind of encoding or other string options that will result in better alignment than what I've tried with Rpad?

Thanks in advance,
George

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Looks are important
@ 2003-11-12 23:19  Louise Cofield <lcofield@box-works.com>
  parent: George Weaver <georgew1@mts.net>
  1 sibling, 1 reply; 7+ messages in thread

From: Louise Cofield @ 2003-11-12 23:19 UTC (permalink / raw)
  To: 'George Weaver' <georgew1@mts.net>; pgsql-sql

Try the TRIM function or the LTRIM function:
 
SELECT RPAD(no,30,' ') || TRIM(tableb.kind) FROM tablea 
WHERE tablea.kind = tableb.kind
 
Louise

-----Original Message-----
From: pgsql-sql-owner@postgresql.org
[mailto:pgsql-sql-owner@postgresql.org] On Behalf Of George Weaver
Sent: Wednesday, November 12, 2003 3:12 PM
To: pgsql-sql@postgresql.org
Subject: [SQL] Looks are important


Hi Everyone,
 
I am trying to concatenate two fields through a query:
 
SELECT RPAD(no,30,' ') || tableb.kind FROM tablea 
WHERE tablea.kind = tableb.kind
 
The result gives (for example):
 
4595448                       Green
5966                          Yellow
106-60033                     Green
15-94-387                     Red
217-991173                    Blue
 
What I would like to have is better alignment:
 
4595448                     Green
5966                          Yellow
106-60033                  Green
15-94-387                   Red
217-991173                 Blue
 
Is there some kind of encoding or other string options that will result
in better alignment than what I've tried with Rpad?
 
Thanks in advance,
George
 
 
 
 

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Looks are important
@ 2003-11-12 23:56  Josh Berkus <josh@agliodbs.com>
  parent: George Weaver <georgew1@mts.net>
  1 sibling, 0 replies; 7+ messages in thread

From: Josh Berkus @ 2003-11-12 23:56 UTC (permalink / raw)
  To: George Weaver <georgew1@mts.net>; pgsql-sql

George,

> SELECT RPAD(no,30,' ') || tableb.kind FROM tablea 
> WHERE tablea.kind = tableb.kind

Try SELECT RPAD(no, (35 - LENGTH(tableb.kind)), ' ')

-- 
-Josh Berkus
 Aglio Database Solutions
 San Francisco




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Looks are important
@ 2003-11-13 03:14  George Weaver <georgew1@mts.net>
  parent: Louise Cofield <lcofield@box-works.com>
  0 siblings, 2 replies; 7+ messages in thread

From: George Weaver @ 2003-11-13 03:14 UTC (permalink / raw)
  To: Josh Berkus <josh@agliodbs.com>; pgsql-sql; Louise Cofield <lcofield@box-works.com>

MessageHi Louise, Josh,

Thanks for the suggestions.

What I'm trying to accomplish is to have a space between no and kind.  Length(no) can vary.  I would like all the kinds to line up evenly when displayed, with a space between no and kind.  But when I RPAD no (to try and get an even starting point for kind),   the ' 's are not quite the same width as an ordinary number or letter.  Thus the physical display length of "30 characters" (padded) can vary from row to row. The result is that the kinds don't necessary line up neatly.  I need to concatenate the two as they are being displayed as one column in a drop down combobox.

Is what I'm trying to do possible???

George
  ----- Original Message ----- 
  From: Louise Cofield 
  To: 'George Weaver' ; pgsql-sql@postgresql.org 
  Sent: Wednesday, November 12, 2003 5:19 PM
  Subject: RE: [SQL] Looks are important


  Try the TRIM function or the LTRIM function:

  SELECT RPAD(no,30,' ') || TRIM(tableb.kind) FROM tablea 
  WHERE tablea.kind = tableb.kind

  Louise
    -----Original Message-----
    From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of George Weaver
    Sent: Wednesday, November 12, 2003 3:12 PM
    To: pgsql-sql@postgresql.org
    Subject: [SQL] Looks are important


    Hi Everyone,

    I am trying to concatenate two fields through a query:

    SELECT RPAD(no,30,' ') || tableb.kind FROM tablea 
    WHERE tablea.kind = tableb.kind

    The result gives (for example):

    4595448                       Green
    5966                          Yellow
    106-60033                     Green
    15-94-387                     Red
    217-991173                    Blue

    What I would like to have is better alignment:

    4595448                     Green
    5966                          Yellow
    106-60033                  Green
    15-94-387                   Red
    217-991173                 Blue

    Is there some kind of encoding or other string options that will result in better alignment than what I've tried with Rpad?

    Thanks in advance,
    George

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Looks are important
@ 2003-11-13 03:31  Tom Lane <tgl@sss.pgh.pa.us>
  parent: George Weaver <georgew1@mts.net>
  1 sibling, 1 reply; 7+ messages in thread

From: Tom Lane @ 2003-11-13 03:31 UTC (permalink / raw)
  To: George Weaver <georgew1@mts.net>; +Cc: Josh Berkus <josh@agliodbs.com>; pgsql-sql@postgresql.org, "Louise Cofield" <lcofield@box-works.com>

"George Weaver" <georgew1@mts.net> writes:
> ... the ' 's are not quite the same width as=
>  an ordinary number or letter.  Thus the physical display length of "30 cha=
> racters" (padded) can vary from row to row. The result is that the kinds do=
> n't necessary line up neatly.  I need to concatenate the two as they are be=
> ing displayed as one column in a drop down combobox.

Use a fixed-width font.

> Is what I'm trying to do possible???

Not with a variable-width font that you haven't even told us the exact
character widths of ...

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Looks are important
@ 2003-11-13 13:29  George Weaver <georgew1@mts.net>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: George Weaver @ 2003-11-13 13:29 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Josh Berkus <josh@agliodbs.com>; pgsql-sql; Louise Cofield <lcofield@box-works.com>

Hi Tom,

Switching to a fixed-width font did the trick.

Thanks for the help.

George

----- Original Message ----- 
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "George Weaver" <georgew1@mts.net>
Cc: "Josh Berkus" <josh@agliodbs.com>; <pgsql-sql@postgresql.org>; "Louise
Cofield" <lcofield@box-works.com>
Sent: Wednesday, November 12, 2003 9:31 PM
Subject: Re: [SQL] Looks are important


> "George Weaver" <georgew1@mts.net> writes:
> > ... the ' 's are not quite the same width as=
> >  an ordinary number or letter.  Thus the physical display length of "30
cha=
> > racters" (padded) can vary from row to row. The result is that the kinds
do=
> > n't necessary line up neatly.  I need to concatenate the two as they are
be=
> > ing displayed as one column in a drop down combobox.
>
> Use a fixed-width font.
>
> > Is what I'm trying to do possible???
>
> Not with a variable-width font that you haven't even told us the exact
> character widths of ...
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Looks are important
@ 2003-11-13 15:22  Louise Cofield <lcofield@box-works.com>
  parent: George Weaver <georgew1@mts.net>
  1 sibling, 0 replies; 7+ messages in thread

From: Louise Cofield @ 2003-11-13 15:22 UTC (permalink / raw)
  To: 'George Weaver' <georgew1@mts.net>; 'Josh Berkus' <josh@agliodbs.com>; pgsql-sql

Using a fixed-width font as Tom suggests, concatenate an additional
space between the no field and the kind field:
 
SELECT RPAD(no,30,' ') || ' ' || TRIM(tableb.kind) FROM tablea 
WHERE tablea.kind = tableb.kind
 
Louise

-----Original Message-----
From: pgsql-sql-owner@postgresql.org
[mailto:pgsql-sql-owner@postgresql.org] On Behalf Of George Weaver
Sent: Wednesday, November 12, 2003 8:15 PM
To: Josh Berkus; pgsql-sql@postgresql.org; Louise Cofield
Subject: Re: [SQL] Looks are important


Hi Louise, Josh,
 
Thanks for the suggestions.
 
What I'm trying to accomplish is to have a space between no and kind.
Length(no) can vary.  I would like all the kinds to line up evenly when
displayed, with a space between no and kind.  But when I RPAD no (to try
and get an even starting point for kind),   the ' 's are not quite the
same width as an ordinary number or letter.  Thus the physical display
length of "30 characters" (padded) can vary from row to row. The result
is that the kinds don't necessary line up neatly.  I need to concatenate
the two as they are being displayed as one column in a drop down
combobox.
 
Is what I'm trying to do possible???
 
George

----- Original Message ----- 
From: Louise  <mailto:lcofield@box-works.com> Cofield 
To: 'George Weaver' <mailto:georgew1@mts.net>  ;
pgsql-sql@postgresql.org 
Sent: Wednesday, November 12, 2003 5:19 PM
Subject: RE: [SQL] Looks are important


Try the TRIM function or the LTRIM function:
 
SELECT RPAD(no,30,' ') || TRIM(tableb.kind) FROM tablea 
WHERE tablea.kind = tableb.kind
 
Louise

-----Original Message-----
From: pgsql-sql-owner@postgresql.org
[mailto:pgsql-sql-owner@postgresql.org] On Behalf Of George Weaver
Sent: Wednesday, November 12, 2003 3:12 PM
To: pgsql-sql@postgresql.org
Subject: [SQL] Looks are important


Hi Everyone,
 
I am trying to concatenate two fields through a query:
 
SELECT RPAD(no,30,' ') || tableb.kind FROM tablea 
WHERE tablea.kind = tableb.kind
 
The result gives (for example):
 
4595448                       Green
5966                          Yellow
106-60033                     Green
15-94-387                     Red
217-991173                    Blue
 
What I would like to have is better alignment:
 
4595448                     Green
5966                          Yellow
106-60033                  Green
15-94-387                   Red
217-991173                 Blue
 
Is there some kind of encoding or other string options that will result
in better alignment than what I've tried with Rpad?
 
Thanks in advance,
George
 
 
 
 

^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2003-11-13 15:22 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-11-12 22:12 Looks are important George Weaver <georgew1@mts.net>
2003-11-12 23:19 ` Louise Cofield <lcofield@box-works.com>
2003-11-13 03:14   ` George Weaver <georgew1@mts.net>
2003-11-13 03:31     ` Tom Lane <tgl@sss.pgh.pa.us>
2003-11-13 13:29       ` George Weaver <georgew1@mts.net>
2003-11-13 15:22     ` Louise Cofield <lcofield@box-works.com>
2003-11-12 23:56 ` Josh Berkus <josh@agliodbs.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox