Re: Uppercase and Lowercase

From: "Bart Degryse" <Bart(dot)Degryse(at)indicator(dot)be>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Uppercase and Lowercase
Date: 2007-02-19 16:05:03
Message-ID: 45D9D8BE.A3DD.0030.0@indicator.be
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Robert is right of course. You can eg use a trigger to do that...

I haven't tested, but I guess something like this would do what you want whenever you insert records in your table

CREATE OR REPLACE FUNCTION "public"."func_change_case" () RETURNS trigger AS
$body$
BEGIN
NEW.pa_indirizzo := initcap(NEW.pa_indirizzo);
RETURN NEW;
END;
$body$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

CREATE TRIGGER "TRIG_yourtablename" BEFORE INSERT
ON "public"."yourtablename" FOR EACH ROW
EXECUTE PROCEDURE "public"."func_change_case"();

>>> "Hiltibidal, Robert" <Robert(dot)Hiltibidal(at)argushealth(dot)com> 2007-02-19 16:55 >>>

Exactly. Since its only a select group of words this query applies to its better to correct for this before the information goes into the database.

From:pgsql-sql-owner(at)postgresql(dot)org [mailto:pgsql-sql-owner(at)postgresql(dot)org] On Behalf Of Bart Degryse
Sent: Monday, February 19, 2007 9:49 AM
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] Uppercase and Lowercase

Of course it does. That's what you ask your query to do. You only used the wrong operator for string concatenation, which is why it didn't seem to work. But your query will not do this for each word in a field. For that you need a function or regular expressions. I suggest you try

select initcap(pa_indirizzo) from ..

Please always reply to pgsql-sql(at)postgresql(dot)org and not to the senders email address.

>>> "Shavonne Marietta Wijesinghe" <shavonne(dot)marietta(at)studioform(dot)it> 2007-02-19 16:39 >>>

Hey thanks Bart. it worked ;)

but sadly what it does is changes "VIA SENATO" in to "Via senato" but what i need is "Via Senato"

Anyoneeeeeee??

Shavonne Wijesinghe
----- Original Message -----

From:Bart Degryse ( mailto:Bart(dot)Degryse(at)indicator(dot)be )

To:pgsql-sql(at)postgresql(dot)org

Sent:Monday, February 19, 2007 4:25 PM

Subject:Re: [SQL] Uppercase and Lowercase

Replace && by ||

>>> "Shavonne Marietta Wijesinghe" <shavonne(dot)marietta(at)studioform(dot)it> 2007-02-19 16:22 >>>

Hello

In my PostgreSQL database i have records inserted in Uppercase.

For example: VIA SENATO

What i want is to change them to "Via Senato". Ofcourse i'm looking for a automatico way. I wrote this code update registro1 set pa_indirizzo = upper(substr(pa_indirizzo, 1, 1)) && lower(substr(pa_indirizzo, 2, length(pa_indirizzo) - 1)) But it doesn't work.

When i run only update registro1 set pa_indirizzo = upper(substr(pa_indirizzo, 1, 1)) It gets me the first letter and when i run

update registro1 set pa_indirizzo = lower(substr(pa_indirizzo, 2, length(pa_indirizzo) - 1)) I get from the second letter to the last. But when i join them them don't work..

Anyone got any idea??

Thanks

Shavonne Wijesinghe

PRIVILEGED AND CONFIDENTIAL
This email transmission contains privileged and confidential information intended only for the use of the individual or entity named above. If the reader of the email is not the intended recipient or the employee or agent responsible for delivering it to the intended recipient, you are hereby notified that any use, dissemination or copying of this email transmission is strictly prohibited by the sender. If you have received this transmission in error, please delete the email and immediately notify the sender via the email return address or mailto:postmaster(at)argushealth(dot)com(dot) Thank you.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Salman Tahir 2007-02-19 16:58:26 cartesian product
Previous Message Alvaro Herrera 2007-02-19 15:54:06 Re: Uppercase and Lowercase