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 7837081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:27:23+00:00 2026-06-02T14:27:23+00:00

I have two tables, pattern and pattern_optimized . Some of the fields in the

  • 0

I have two tables, pattern and pattern_optimized. Some of the fields in the pattern table are defined as BIGINT(20) DEFAULT '-1', which is way too big for the data they hold; Additionally, -1 is used as “not set” (zero is a valid value) – no other negative values are used otherwise.

The pattern_optimized table uses a new data format for these rows, defining them as INT(10) UNSIGNED DEFAULT NULL. I would now like to copy the data from pattern to the pattern_optimized table.

This would be easily done using INSERT INTO pattern_optimized SELECT * FROM pattern, but obviously all negative values are out of range now, resulting in warnings like this:

100 row(s) affected, 64 warning(s): 
1264 Out of range value for column 'version' at row 1 
1264 Out of range value for column 'triggered' at row 1
...
Records: 100  Duplicates: 0  Warnings: 357

My first idea was to create a BEFORE INSERT trigger as follows:

CREATE TRIGGER `negativeValueFix` BEFORE INSERT ON `pattern_optimized`
FOR EACH ROW
BEGIN
    IF new.version < 0 THEN 
        SET new.version = NULL; 
    END IF;
    -- ...
END

but unfortunately this doesn’t help either: The same warning pops up and all values that used to be -1 in the original table become 0 in the new table (instead of NULL, which is – apart from being implemented in the trigger – also the default for the row).
It seems that MySQL converts the value even before the trigger.

I know that I can solve this problem using a temporary table but I’d rather not do that. The pattern table is unpleasantly large and I don’t want to do a stored procedure just for that.

Is there any other way or am I missing some simple point?

EDIT: There are quite alot columns in the original table that suffer from the SIGNED problem, so I was hoping to somewhat automate that.

  • 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-02T14:27:25+00:00Added an answer on June 2, 2026 at 2:27 pm

    Could you use a case statement? Something like:


    INSERT INTO pattern_optimized
    SELECT
    CASE version
    WHEN -1 THEN null
    ELSE version
    END CASE AS version
    FROM pattern

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

Sidebar

Related Questions

I have two tables, for example: Table A Table B ======= ======= Name |
I have two tables: a schedule table that contains information about how an employee
I have two tables, I want to search TermID in Table-A through TermID in
I have two tables in this project of mine. One table is for the
I have two tables, custassets and tags . To generate some test data I'd
i have two tables products and reviews each product has several reviews linked by
I have two tables : teachers (teacher_id,teacher_name) courses (teacher_id,course_id) And I need to display
I have two tables on a webform. On a button click I want to
i have two tables both are related with primary-foreign key ralation and i have
I have two tables, the first has a primary key that is an identity,

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.