pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feedrtrim
5+ messages / 3 participants
[nested] [flat]
* rtrim
@ 2003-01-22 06:25 ryanne cruz <ryanne.cruz@up.edu.ph>
0 siblings, 3 replies; 5+ messages in thread
From: ryanne cruz @ 2003-01-22 06:25 UTC (permalink / raw)
To: pgsql-php
hi list.
if there's anyone here who's familiar with teh rtrim function, please i need
help.
i have a table that has a column in it that has data in this format:
California, USA
Nevada, USA
.
.
.
when i use rtrim to erase the ", USA" part, it only sometimes work. a sample
result would be:
California
Nevad
my query statement is:
update table set name=rtrim(name,', USA');
why is it that it only works sometimes?
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: rtrim
@ 2003-01-22 06:41 ryanne cruz <ryanne.cruz@up.edu.ph>
parent: ryanne cruz <ryanne.cruz@up.edu.ph>
2 siblings, 0 replies; 5+ messages in thread
From: ryanne cruz @ 2003-01-22 06:41 UTC (permalink / raw)
To: jlarson@candlefire.org <jlarson@candlefire.org>; pgsql-php
Thanks Jason.
but my data in that column varies. what i mean is that not all data ends in ",
USA". some ends in ", Italy" or ", England". if i understood your code right,
this only works when all my data ends with ", USA" or any country with 3
letters on it. anymore ideas?
Quoting Jason k Larson <jlarson@candlefire.org>:
> rtrim and ltrim are used to remove whitespaces. I'm not certain why you
> are getting unpredictable behavior, but try this instead.
>
> $column = substr ($column, 0, strlen($column)-5); // 5 = ', USA'
>
> http://www.php.net/manual/en/function.substr.php
>
> HTH,
> Jason k Larson
>
>
> ryanne cruz wrote:
>
> >
> > hi list.
> >
> > if there's anyone here who's familiar with teh rtrim function, please
> > i need
> > help.
> >
> > i have a table that has a column in it that has data in this format:
> >
> > California, USA
> > Nevada, USA
> > .
> > .
> > .
> >
> > when i use rtrim to erase the ", USA" part, it only sometimes work. a
> > sample
> > result would be:
> >
> > California
> > Nevad
> >
> > my query statement is:
> > update table set name=rtrim(name,', USA');
> >
> > why is it that it only works sometimes?
>
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: rtrim
@ 2003-01-22 07:31 Andrew McMillan <andrew@catalyst.net.nz>
parent: ryanne cruz <ryanne.cruz@up.edu.ph>
2 siblings, 1 reply; 5+ messages in thread
From: Andrew McMillan @ 2003-01-22 07:31 UTC (permalink / raw)
To: ryanne cruz <ryanne.cruz@up.edu.ph>; +Cc: pgsql-php
On Wed, 2003-01-22 at 19:25, ryanne cruz wrote:
> hi list.
>
> if there's anyone here who's familiar with teh rtrim function, please i need
> help.
It depends on the datatypes in use.
If you use a type like "CHAR(32)" it will always be right-padded with
spaces. Whereas if you use a type like "TEXT" or "VARCHAR(32)" it will
be stored as you enter it (it may still have some trailling spaces.
Now, when you use the rtrim() function, but insert the result into a
CHAR(N) column, all those spaces will just be stuck straight back on
again. This is likely to be what is happening in your case.
Regards,
Andrew.
>
> i have a table that has a column in it that has data in this format:
>
> California, USA
> Nevada, USA
> .
> .
> .
>
> when i use rtrim to erase the ", USA" part, it only sometimes work. a sample
> result would be:
>
> California
> Nevad
>
> my query statement is:
> update table set name=rtrim(name,', USA');
>
> why is it that it only works sometimes?
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
--
---------------------------------------------------------------------
Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St, Wellington
WEB: http://catalyst.net.nz/ PHYS: Level 2, 150-154 Willis St
DDI: +64(4)916-7201 MOB: +64(21)635-694 OFFICE: +64(4)499-2267
Survey for nothing with http://survey.net.nz/
---------------------------------------------------------------------
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: rtrim
@ 2003-01-22 07:55 ryanne cruz <ryanne.cruz@up.edu.ph>
parent: Andrew McMillan <andrew@catalyst.net.nz>
0 siblings, 0 replies; 5+ messages in thread
From: ryanne cruz @ 2003-01-22 07:55 UTC (permalink / raw)
To: pgsql-php@postgresql.org, Andrew McMillan <andrew@catalyst.net.nz>
in both my of my tables, the original and the table where i will insert the
column without the ", USA", the type of the columns are character varying. is
that the same with varchar?
Quoting Andrew McMillan <andrew@catalyst.net.nz>:
> On Wed, 2003-01-22 at 19:25, ryanne cruz wrote:
> > hi list.
> >
> > if there's anyone here who's familiar with teh rtrim function, please i
> need
> > help.
>
> It depends on the datatypes in use.
>
> If you use a type like "CHAR(32)" it will always be right-padded with
> spaces. Whereas if you use a type like "TEXT" or "VARCHAR(32)" it will
> be stored as you enter it (it may still have some trailling spaces.
>
> Now, when you use the rtrim() function, but insert the result into a
> CHAR(N) column, all those spaces will just be stuck straight back on
> again. This is likely to be what is happening in your case.
>
> Regards,
> Andrew.
> >
> > i have a table that has a column in it that has data in this format:
> >
> > California, USA
> > Nevada, USA
> > .
> > .
> > .
> >
> > when i use rtrim to erase the ", USA" part, it only sometimes work. a
> sample
> > result would be:
> >
> > California
> > Nevad
> >
> > my query statement is:
> > update table set name=rtrim(name,', USA');
> >
> > why is it that it only works sometimes?
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 5: Have you checked our extensive FAQ?
> >
> > http://www.postgresql.org/users-lounge/docs/faq.html
> --
> ---------------------------------------------------------------------
> Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St, Wellington
> WEB: http://catalyst.net.nz/ PHYS: Level 2, 150-154 Willis St
> DDI: +64(4)916-7201 MOB: +64(21)635-694 OFFICE: +64(4)499-2267
> Survey for nothing with http://survey.net.nz/
> ---------------------------------------------------------------------
>
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: rtrim
@ 2003-01-22 13:42 Bruno Wolff III <bruno@wolff.to>
parent: ryanne cruz <ryanne.cruz@up.edu.ph>
2 siblings, 0 replies; 5+ messages in thread
From: Bruno Wolff III @ 2003-01-22 13:42 UTC (permalink / raw)
To: ryanne cruz <ryanne.cruz@up.edu.ph>; +Cc: pgsql-php
On Wed, Jan 22, 2003 at 14:25:28 +0800,
ryanne cruz <ryanne.cruz@up.edu.ph> wrote:
>
> hi list.
>
> if there's anyone here who's familiar with teh rtrim function, please i need
> help.
>
> i have a table that has a column in it that has data in this format:
>
> California, USA
> Nevada, USA
You may want to keep the country as a separate column.
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2003-01-22 13:42 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-01-22 06:25 rtrim ryanne cruz <ryanne.cruz@up.edu.ph>
2003-01-22 06:41 ` ryanne cruz <ryanne.cruz@up.edu.ph>
2003-01-22 07:31 ` Andrew McMillan <andrew@catalyst.net.nz>
2003-01-22 07:55 ` ryanne cruz <ryanne.cruz@up.edu.ph>
2003-01-22 13:42 ` Bruno Wolff III <bruno@wolff.to>
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