Re: argh... can't cast varchar to int - Mailing list pgsql-general

From Oliver Elphick
Subject Re: argh... can't cast varchar to int
Date
Msg-id 1038192476.2847.4.camel@linda.lfix.co.uk
Whole thread Raw
In response to argh... can't cast varchar to int  (Matthew Nuzum <cobalt@bearfruit.org>)
List pgsql-general
On Mon, 2002-11-25 at 02:28, Matthew Nuzum wrote:
> I have a table that has (among other things) two values, one named
> ftr_type and the other ftr_data.
>
> Depending on the value of ftr_type, ftr_data may contain the value of a
> primary key in another table.  Because sometimes there is another table
> and sometimes there isn't, ftr_data is a varchar.
>
Why not make it integer but leave its value as NULL if there is no other
table?

Alternatively, cast it to text first:

        junk=# select CAST('22'::text as int4);
         int4
        ------
           22
        (1 row)

--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight, UK                             http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "Let us therefore come boldly unto the throne of grace,
      that we may obtain mercy, and find grace to help in
      time of need."             Hebrews 4:16


pgsql-general by date:

Previous
From: Matthew Nuzum
Date:
Subject: argh... can't cast varchar to int
Next
From: "SZŰCS Gábor"
Date:
Subject: query visibility - trigger order - bug?