Thread: Casting help

Casting help

From
"Mitch Vincent"
Date:
hhs=# INSERT INTO applicants_test (SELECT app_id ,old_id ,emp_id ,inv_id
,createdate ,updatedon ,todelete ,appstatus ,apptype ,infosent ,empinitials
,firstname ,lastname ,salutation ,fontype1 ,fonnumber1 ,fonext1 ,fontype2
,fonnumber2 ,fonext2 ,fontype3 ,fonnumber3 ,fonext3 ,address1 ,address2
,city ,state ,postal ,country ,homestate ,email ,careerdate ,degree1
,degreedate1 ,gpa1 ,university1 ,degree2 ,degreedate2 ,gpa2 ,university2
,startdate ,currentsalary ,degreecode ,industrycode ,title ,company
,companydiv ,preemploy ,minority as processtype ,inunion ,prodnotes ,sk1
,sk2 ,sk3 ,sk4 ,sic1 ,sic2 ,sic3 ,certificates ,clearance ,languages
,desiredsalary ,minimumsalary ,whyseeking ,followdate ,personalnotes as
technotes ,technotes as personalnotes ,relonote ,follownote ,profile
,relopref1 ,relopref2 ,relo_states ,source ,upinitials  FROM applicants);
ERROR:  Attribute 'processtype' is of type 'varchar' but expression is of
type 'bool'
        You will need to rewrite or cast the expression
hhs=#

And

if I try to cast minority to varchar (or anything else for that matter) I
get

ERROR:  Cannot cast type 'bool' to 'varchar'

Is there any way to get the above to work? I have a client down and need
this (or something like this) to straighten out his data tables... Thanks!

-Mitch


Re: Casting help

From
Peter Eisentraut
Date:
Mitch Vincent writes:

> if I try to cast minority to varchar (or anything else for that matter) I
> get
>
> ERROR:  Cannot cast type 'bool' to 'varchar'

Try:  CASE WHEN minority THEN 'value of true' ELSE 'value if false' END

--
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/


Re: Casting help

From
Tom Lane
Date:
"Mitch Vincent" <mitch@venux.net> writes:
> if I try to cast minority to varchar (or anything else for that matter) I
> get
> ERROR:  Cannot cast type 'bool' to 'varchar'

There's always

    CASE WHEN minority THEN 't' ELSE 'f' END

            regards, tom lane