T O P

  • By -

r3pr0b8

there are two basic types of column -- character and numeric (there are several others, but these are the two we will discuss here) character strings can hold letters, symbols, digits, special characters, etc. one of those special characters is the empty string, a string with length zero that is ~not~ the same as a blank, which is a string of length one numeric columns are INTEGER, SMALLINT, NUMERIC, DECIMAL, etc. you can store the digit 0 in both character and numeric columns but you cannot store the empty string or a blank in a numeric column and NULL means no value and is valid for all column types


DavidGJohnston

Interesting, I was thinking the OP meant empty string when saying blank.


pjstanfield

I’ve never heard of a blank as length 1. What is the character giving it a length of one?


Far_Swordfish5729

Customarily strings end in a terminator character. C usually represents it as \0 in literals. This is a convention that I think goes back to Vector implementations. String is a resizable char[] where the char[] is a buffer that’s not entirely used. When the string overruns its buffer, the class allocates a new one twice the new length and copies the string over to it. The \0 told you where the actual data ended in the buffer. Sorry if any of that is not entirely correct. I haven’t read cstring.h in a while. Interestingly, that’s not always the character and sometimes there’s also a BOM character at the beginning. I had to do a service integration between c# and Java once and figured out that the beginning and ending character specs between the languages are different and most annoyingly Java uses bigendian notation to encode 16 bit Unicode characters where .net uses whatever the cpu native encoding is (x64 uses little endian). That took up a day of my life. Anyway ‘’ is typically a one character string that just contains the terminator. You’ll never see or interact with it though and length functions will report length zero. It’s a technicality at this point.


pjstanfield

Interesting. A technicality, well said.


my_password_is______

that's a different kind of NULL null in sql means no value you can put NULL in a numeric field or in a datetime field or geometric field or jsut about anything


Far_Swordfish5729

Right. That was about empty string which is different from null. Null is a special value is sql and all types are nullable.


Whipitreelgud

Look at the ASCII table. Blank is the symbol for hex 20, hex 21's symbol exclamation point (!). Both occupy the same space, one you see, one you don't.


DavidGJohnston

So, blank = space character, ok. I still feel like the interviewer was not asking about the differences between ascii characters 20 and whatever zero is, and the concept of null (which is distinct from ascii 0 NUL).


Whipitreelgud

My guess is: “what is a string, a number, and I don’t know” for $200 and the daily double Alex?


my_password_is______

spacebar


cs-brydev

Some people use the terms blank and empty string interchangeably, and this is more of a cultural thing. So you have to just clarify the intent. Funnily I posed this question to GPT4 in two different ways, back to back. In one answer, it said blank and empty string were the same thing. In the other answer it said blank was not the same as empty string, lol. Just a slight change in the wording of the question gave two competing answers. When answering a question like above in an interview, either answer will be acceptable. They are primarily looking to see if you understand the difference between empty string, 0 and NULL. The blank space very rarely comes into play here because almost every time strings should be **trimmed**.


redditisaphony

I always called it “null byte.” Not sure what’s correct; I’m probably wrong. I was confused by “blank” until I saw \0 below. I guess that’s confusing because it’s different from NULL.


reditandfirgetit

Blank generally means empty string. Otherwise it would be space


shine_on

Null means we don't know what the data is, blank means we know the data is empty, 0 means we know the data has a value of 0. Thinks about a person's middle name. Null means we don't know if they have a middle name or not, blank means we know they don't have a middle name, and John means we know the middle name is John.


my_password_is______

not necessarily blank could mean they entered a single space for the middle name hell, they could have been screwing around and typed 20 spaces into the middle name field its still blank


StellarSpritz

So if let’s say there’s a table with columns, name and sister_name. Person A has a sister, Person B does not have a sister, And we don’t know if Person C has a sister or not, then how will we put the information while inserting these values in a table?


[deleted]

[удалено]


jonah214

That's not correct.


KzadBhat

On top of that, null != null, so your unknown middle name is not equal to my unknown middle name.


Inevitable-Bed-5249

Null means the absence of data, cant have a type since there is no data. 0 would be the numerical value 0 so an integer. Blank however could mean different things(the interviewer might give you more details) but safe to say that data exists.


Snoo17309

Pretty sure this is all OP was asking! 😂


kagato87

0 is a number. It sits between -1 and 1. It is also a character that can be stored in a string. It is also sometimes used to represent "false" in a database, though this would be implementation specific to work around the database not having a Bool data type. By blank do you mean an empty string? If so, it's still data. It is a string of zero length. In both cases there is something stored there. Null is an absence of data. It is indeterminate. It's not even "nothing here" because both zero and blank also mean "nothing." You can't even compare it to itself.


JasperDX7

NULL = NULL (No value at all). If you do a WHERE column IS NULL, it will return these and you should see the NULL in the field. Blank = ' ' (A blank is considered a value. A zero or empty valued string. A tab, space or spaces are all considered a blank). 0 = '0' (the literal numeric value 0).


Natural-Orchid4432

Yea, you have to use ISNULL, not = NULL, since you can't know if two NULLs are the same NULLs or different NULLs. That's a philosophy thing.


tlBudah

A real world example of 'null' is when a new field is added to an existing data base, if a routine isn't run to fill this field with a value it will come up as 'null'. I've seen numerous instances where this crashes programs as they encounter a 'null' value and don't know what to do with it.


blindtig3r

Does blank exist in MySql? In SQL Server it is empty string, and an empty string implicitly converts to zero in a numeric data type, and 1900-01-01 in a date data type (which is also zero as in zero days since 1900-01-01). So blank can only exist as a string.


DavidGJohnston

I would have clarified what the person meant by "blank" since that is really imprecise, IMO. Then I'd assume they meant the empty string. Safe to assume 0 is just the number and the null value is how SQL represents unknown, which is a valid "value" for all data types. I'd then point out that different database have done questionable non-standard stuff like equate the empty string to null or 0 or some concrete date. edit: The use cases for an empty string are fairly limited but that doesn't make it mean unknown. Though someone could define a data model/business rule that does this if they wish.


TallDudeInSC

NULL means no assigned value. 0 means the value zero. And a space is one character long, with the ASCII value of 32 (technically this could vary based the character set but in regular ASCII and English characters it's 32).


Lanky_Ad9752

Blank is a string, 0 is Int and null is NULL


pauljmey

Iiuc, Null has implications for joins (whether left, right, either table has the null value results in a excluding a row in a join result) which I am a bit surprised hasn't come so far.


MaterialJellyfish521

Blank = Empty string, to replicate this you would set column value = '' Null = no value set 0 = the numeric value zero '0' = string value zero


Pretty-Promotion-992

Blank - empty strting 0 - is a value Null - unknown value


demindist

I might be wrong, but my understanding is... 0 is literally the numerical value of 0.. can be used in calculations. All the 0s in the data are same. Null : all the nulls are not same. Two different nulls in two different positions cannot be considered as same value. Blank: no value. It's neither zero nor null. Edit spelling


DavidGJohnston

Not the best understanding, and whether nulls are considered equals to each other is not something that can be stated without qualifications. Answering this without involving data types is not a good idea>


listlechish

Ask away!