ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
Actually, NULL is a value and you can test for it; e.g., ... set somecolumn = 0 where blah is null ... Specifically is there a catchall value, well, no unless you want to consider NULL as such (and it pretty much is).
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
You may want to consider altering your tables so that numeric columns default to zero (integer 0, float 0.0) and important character columns (for example, fname and lname) are not null; i.e., a value is required, and non-critical character columns default to NULL. The idea is to not add a bunch of stuff that just takes up space but at the same time let the engine force you to make entries in critical columns. Defaulting a numeric column to zero will only take up storage space the size of the given data type (an integer and a float typically take up four bytes, a double typically eight bytes). This starts to matter when you get a few 10's of million rows in your tables. That a character is null doesn't really matter because you can test for that; i.e., the result of a query is either "something" or "nothing" and you take appropriate action depending upon that.
SQL is kind of bassackwards to the way you normally think -- you tend to think in terms of "if condition do this else do that," and SQL isn't quite the same. So, you don't take action after a query in SQL, you take action as part of the query.
Something like this, say
update tabname
set col_a = "this string value"
where col_a is null
and col_b = 123
and col_c = 0;
So, the content of col_a will only be changed to "this string value" if col_a is null and the other two values are as stated. Not quite the same thing as "if - else."
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.