Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8903505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:53:09+00:00 2026-06-15T01:53:09+00:00

The ‘thread’ column in an old Drupal 4.7 Comments table is varchar(255), and I

  • 0

The ‘thread’ column in an old Drupal 4.7 Comments table is varchar(255), and I need to convert it to bigint(20) to make it work for the ‘comment_parent’ column in a WordPress wp_comments table.

I’ve tried various Cast and Convert commands I’ve seen and always get syntax errors.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:53:10+00:00Added an answer on June 15, 2026 at 1:53 am

    This works in SQL Server:

    create table Comments 
    (
        [thread] nvarchar(255)
    ) 
    
    insert comments 
    select '1' 
    union select '2' 
    union select '3' 
    union select '4' 
    union select '5' 
    union select 'x' 
    
    select 
        case 
            when ISNUMERIC([thread]) > 0 
                then CAST([thread] as bigint) 
            else 
                null 
        end colAsBigInt 
        , [thread] colAsNvarChar 
    from comments
    

    http://sqlfiddle.com/#!6/337eb/1

    For MySQL try:

    create table if not exists Comments 
    (
        thread varchar(255) character set UTF8 not null
    );
    
    insert comments(thread) values ('1');
    insert comments(thread) values ('2');
    insert comments(thread) values ('3');
    insert comments(thread) values ('4');
    insert comments(thread) values ('5');
    insert comments(thread) values ('6.1');
    insert comments(thread) values ('x');
    
    select 
        case 
            when thread  REGEXP ('^(-|\\+)?([0-9]+\\.[0-9]*|[0-9]*\\.[0-9]+|[0-9]+)$') 
                then cast(thread as signed)
            else 
                null 
        end colAsBigInt 
        , thread colAsVarChar 
    from comments
    
    --regex trick from here: http://forums.mysql.com/read.php?60,1907,241284#msg-241284
    --without the regex you'll get 0s instead of nulls for invalid values
    --MySQL's cast only works on certain data types, given here http://www.roseindia.net/sql/mysql-example/mysql-cast.shtml
    

    Runnable MySQL sample here: http://sqlfiddle.com/#!2/6d848/9

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently got a new cable modem from my ISP (Rogers in Canada; old
I need a function that will clean a strings' special characters. I do NOT
I need to clean up various Word 'smart' characters in user input, including but
I have just tried to save a simple *.rtf file with some websites and
I was writing code for dragging mechanism which invokes to wait for small period
I downloaded PostgreSQL from the official website and ran the .dmg installer. After that
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
This is how I get the tags of a body of text. var tags

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.