Обсуждение: VARCHAR to INTEGER conversion

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

VARCHAR to INTEGER conversion

От
Darren Ferguson
Дата:
Hello list

I have a stored procedure that takes in an integer

sp_customer_service_property_descr(INTEGER)

However i have a database field that is a VARCHAR because it can take
either a number that would have to go into this stored procedure or it can
just have normal text depending on the value of another field.

I tried casting the VARCHAR as an INTEGER postgres (V7.2b4) doesn't let me
do this. Now i understand why it is not letting me do this however here is
my question

Does anyone know of a work around so that i can call this function with
the varchar database field.

Thanks in advance

Darren Ferguson



Re: VARCHAR to INTEGER conversion

От
Stephan Szabo
Дата:
On Wed, 16 Jan 2002, Darren Ferguson wrote:

> I have a stored procedure that takes in an integer
>
> sp_customer_service_property_descr(INTEGER)
>
> However i have a database field that is a VARCHAR because it can take
> either a number that would have to go into this stored procedure or it can
> just have normal text depending on the value of another field.
>
> I tried casting the VARCHAR as an INTEGER postgres (V7.2b4) doesn't let me
> do this. Now i understand why it is not letting me do this however here is
> my question
>
> Does anyone know of a work around so that i can call this function with
> the varchar database field.

If the rows you're working with won't have non-numeric values I think you
can do this by casting through text (varchar->text->integer). If the value
may not be a number that will still fail on those rows.



Re: VARCHAR to INTEGER conversion

От
Darren Ferguson
Дата:
On Thu, 17 Jan 2002, Jeff Eckermann wrote:

> PostgreSQL allows for function overloading, i.e. you

Tried to avoid this since you do not want duplicate functions all over the
system. but i had considered a wrapper.

Steve's solution from last night worked in the conversion to text and then
integer so implemented that.

Thank you for the reply though it is very much appreciated

Darren



Re: VARCHAR to INTEGER conversion

От
Jeff Eckermann
Дата:
PostgreSQL allows for function overloading, i.e. you
can create another function with the same name (and
same logic) that takes a VARCHAR parameter.
PostgreSQL will figure out which function you want,
based on the datatype of the parameter that you pass
to it.

IIRC, if you use pl/pgsql for your function, any type
casting required internally in the function (to get to
your return type) will be handled automagically.

--- Darren Ferguson <darren@crystalballinc.com> wrote:
> Hello list
>
> I have a stored procedure that takes in an integer
>
> sp_customer_service_property_descr(INTEGER)
>
> However i have a database field that is a VARCHAR
> because it can take
> either a number that would have to go into this
> stored procedure or it can
> just have normal text depending on the value of
> another field.
>
> I tried casting the VARCHAR as an INTEGER postgres
> (V7.2b4) doesn't let me
> do this. Now i understand why it is not letting me
> do this however here is
> my question
>
> Does anyone know of a work around so that i can call
> this function with
> the varchar database field.
>
> Thanks in advance
>
> Darren Ferguson
>
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please
> send an appropriate
> subscribe-nomail command to majordomo@postgresql.org
> so that your
> message can get through to the mailing list cleanly


__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/