int1?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rick Seeger

    #31
    Re: Char to Int

    [color=blue]
    >[color=green]
    >> Oops, there was a typo in my second example. Still have the problem
    >> tho...
    >>[color=darkred]
    >> > rs=#
    >> > rs=# insert into table2
    >> > rs=# select CAST(my_Id as integer)
    >> > ^^^^
    >> > rs=# from table1;
    >> > ERROR: Cannot cast type character to integer[/color][/color]
    >
    > Try the function to_number().
    >[/color]

    rs=# select to_number(my_Id ,'9999999999999 999') from table1;

    It worked nicely. Thanks.

    --Rick



    ---------------------------(end of broadcast)---------------------------
    TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddres sHere" to majordomo@postg resql.org)

    Comment

    • Rick Seeger

      #32
      Char to Int


      I'm trying to convert a var char to an int. I tried a couple methods
      described in the documentation, but can't seem to get it to work. Any
      thoughts?

      In this example, the field my_id is character varying(16):

      rs=# insert into table2
      rs=# select my_Id::INT
      rs=# from table1;
      ERROR: Cannot cast type character to integer

      rs=#
      rs=# insert into table2
      rs=# select CASE(my_Id as integer)
      rs=# from table1;
      ERROR: Cannot cast type character to integer

      Any help or links to appropriate documentation appreciated!

      --Rick



      ---------------------------(end of broadcast)---------------------------
      TIP 5: Have you checked our extensive FAQ?



      Comment

      • Rick Seeger

        #33
        Re: Char to Int



        -----Original Message-----

        Oops, there was a typo in my second example. Still have the problem
        tho...
        [color=blue]
        > rs=#
        > rs=# insert into table2
        > rs=# select CAST(my_Id as integer)
        > ^^^^
        > rs=# from table1;
        > ERROR: Cannot cast type character to integer
        >[/color]



        ---------------------------(end of broadcast)---------------------------
        TIP 5: Have you checked our extensive FAQ?



        Comment

        • Ron Johnson

          #34
          Re: Char to Int

          On Tue, 2003-10-14 at 16:11, Rick Seeger wrote:[color=blue]
          > -----Original Message-----
          >
          > Oops, there was a typo in my second example. Still have the problem
          > tho...
          >[color=green]
          > > rs=#
          > > rs=# insert into table2
          > > rs=# select CAST(my_Id as integer)
          > > ^^^^
          > > rs=# from table1;
          > > ERROR: Cannot cast type character to integer[/color][/color]

          Interesting, though, that it works for string constants:

          test1=# select cast('15' as integer);
          int4
          ------
          15
          (1 row)

          test1=# select '15'::integer;
          int4
          ------
          15
          (1 row)


          --
          -----------------------------------------------------------------
          Ron Johnson, Jr. ron.l.johnson@c ox.net
          Jefferson, LA USA

          When Swedes start committing terrorism, I'll become suspicious of
          Scandanavians.


          ---------------------------(end of broadcast)---------------------------
          TIP 4: Don't 'kill -9' the postmaster

          Comment

          • Peter Eisentraut

            #35
            Re: Char to Int

            Rick Seeger writes:
            [color=blue]
            > Oops, there was a typo in my second example. Still have the problem
            > tho...
            >[color=green]
            > > rs=#
            > > rs=# insert into table2
            > > rs=# select CAST(my_Id as integer)
            > > ^^^^
            > > rs=# from table1;
            > > ERROR: Cannot cast type character to integer[/color][/color]

            Try the function to_number().

            --
            Peter Eisentraut peter_e@gmx.net


            ---------------------------(end of broadcast)---------------------------
            TIP 5: Have you checked our extensive FAQ?



            Comment

            • Rick Seeger

              #36
              Re: Char to Int

              [color=blue]
              >[color=green]
              >> Oops, there was a typo in my second example. Still have the problem
              >> tho...
              >>[color=darkred]
              >> > rs=#
              >> > rs=# insert into table2
              >> > rs=# select CAST(my_Id as integer)
              >> > ^^^^
              >> > rs=# from table1;
              >> > ERROR: Cannot cast type character to integer[/color][/color]
              >
              > Try the function to_number().
              >[/color]

              rs=# select to_number(my_Id ,'9999999999999 999') from table1;

              It worked nicely. Thanks.

              --Rick



              ---------------------------(end of broadcast)---------------------------
              TIP 2: you can get off all lists at once with the unregister command
              (send "unregister YourEmailAddres sHere" to majordomo@postg resql.org)

              Comment

              Working...