Can't understand this data type definition - kotlin

I'm currently reading the book atomic kotlin where the definition says Kotlin, A data type provides a set of values from which an expression may take its values and I counter to that saying isn't it the variable of data type which provides the value ? I don't know can anybody please explain ?
A data type provides a set of values from which an expression may take its values

What the sentence is telling you is that a type is a set of values, and when you evaluate an expression of this type, the (single) value of that expression is one value of that set.
isn't it the variable of data type which provides the value ?
A variable of a given data type provides one value when it's read. This is one particular kind of expression of this type. More complex expressions also have a type, and provide one value of that type when evaluated.
The important bit here is that one expression evaluates to one value, while the type is the set of all possible values for expressions of such type.
For example, as mentioned by #Ruthvik, the Int type is the set of all possible integer values between Int.MIN_VALUE and Int.MAX_VALUE.

Related

Checking SQLite value type - numeric vs. textual

Is it possible to filter SQLite column values in SQL based on whether the value is numeric or textual? I have seen references to using CAST for this purpose. However, it appears to be useless as SELECT CAST('1a' AS NUMERIC) passes the check for a numeric type.
The typeof() SQL function is designated for type checking. However, its result depends on both column type definition (according to the official docs) and the format used during insertion. For example, when a number is inserted as a text literal into a NUMERIC column, it is converted into a number if possible, and typeof() will return an appropriate numeric type or text, if conversion did not occur. The TEXT column, on the other hand, stores all numeric literals as text. BLOB column stores textual and numeric literals without interpretation. Therefore, a mixed-type column should be probably declared as BLOB or NUMERIC (depending on whether textual literals needs to be converted to numbers, if possible). With this behavior in mind, typeof() is well suitable for type checking.
Thats just an idea:
SELECT [FilterColumn] FROM [Table] WHERE [FilterColumn]='0' OR (ceiling(log([FilterColumn],10)) =LENGTH([FilterColumn]) AND CAST([FilterColumn] AS INTEGER)>0)
This works for integer numbers where number of digits=log([FilterColumn],10). To distinguish a single letter from casting to 0, [FilterColumn]='0' OR [FilterColumn]>0 included.
I suppose there are more elegant solutions

Coercion vs Casting in standard SQL [duplicate]

This question already has answers here:
What is the difference between casting and coercing?
(7 answers)
Closed 1 year ago.
What is the difference between Coercion and Casting in standard SQL? And what are the use case of those?
The word conversion refers to either implicitly or explicitly changing a value from one data type to another, e.g. a 16-bit integer to a 32-bit integer.
Coercion
The word coercion is used to denote an implicit conversion. A supertype is a common type to which two or more expressions can be coerced.
Casting
The word cast typically refers to an explicit type conversion (as opposed to an implicit conversion) and uses the CAST() function, regardless of whether this is a re-interpretation of a bit-pattern or a real conversion.
So, coercion is implicit, cast is explicit, and conversion is any of them.
Use Case
Generally takes place when in an expression more than one data type is present. In such condition type conversion (type promotion) takes place to avoid loss of data. All the data types of the variables are upgraded to the data type of the variable with largest data type.
If you are trying to assign a value of some type to a location of a different type, you can generate a value of the new type that has a similar meaning to the original. This is coercion. Coercion lets you use the new type by creating a new value that in some way resembles the original. Some coercions may discard data (e.g. converting the int 0x12345678 to the short 0x5678), while others may not (e.g. converting the int 0x00000008 to the short 0x0008, or the long 0x0000000000000008).
Recall that values can have multiple types. If your situation is slightly different, and you only want to select a different one of the value’s types, casting is the tool for the job. Casting simply indicates that you wish to operate on a particular type that a value includes.

PROC SQL error: "ERROR: Expression using equals (=) has components that are of different data types."

I am trying to subset my data with PROC SQL, and it is giving me an error when I use my variable TNM_CLIN_STAGE_GROUP. Example below:
PROC SQL;
create table subset as
select ncdb.*
from ncdb
where YEAR_OF_DIAGNOSIS>2002
AND SEX = 2
AND LATERALITY IN (1,2,3)
AND HISTOLOGY = 8500
AND TNM_CLIN_STAGE_GROUP = 1;
quit;
ERROR: Expression using equals (=) has components that are of different data types.
When I run the same code, but take out the variable TNM_CLIN_STAGE_GROUP, the code works. Anyone know what the problem with that variable's name is?
That error indicates a difference in type. SAS has only two types, numeric and character, so the variable is probably character; verify the specific values, but in general it likely needs quotations (single or double, doesn't matter in this case).
If it is not a hardcoded value, but a value of another variable, you can use PUT to convert to character or INPUT to convert to numeric, whichever is easier to convert based on the data.
SAS in a data step will happily convert this for you, but in SQL and SQL-like (WHERE statements) it does not automatically convert character to numeric and vice versa; you must provide the correct type.
Before doing equality, check what you are trying to compare.
Check the structure of you ncbd table, in particulary field type of TNM_CLIN_STAGE_GROUP
You would see the real type, if its a varchar, you need to use single quote like #JChao suggest in is comment.
If its another type, so you need to adapt the comparator or use cast if you don t have choice.

Code Generater interprets NUMERIC(20,0) as BIGDECIMAL while it should be interpreted as Long

I have a table with a field name "BID" with its data type set as NUMERIC(20,0). Now i know that it will never be a decimal/float value but always be a int/long i.e a natural number.
Is there a way for the code generator to make the variable inside the generated model class a Long as opposed to java.math.BigDecimal which it makes currently. Can it be set in jooq.properties??
This "feature" is currently only available for the Oracle database, where NUMBER is the only numeric type available. Using Oracle with jOOQ, NUMBER(20, 0) would map to java.math.BigInteger instead of java.math.BigDecimal.
This behaviour will also be available for other RDBMS in the next release 1.6.3. See
https://sourceforge.net/apps/trac/jooq/ticket/639
Besides that, overriding of data type mappings in the code generator is currently not possible, but you could use BIGINT as suggested by gbn, if you don't really need 20 decimal digits. BIGINT can hold most 19-digit decimals...

Term to represent all possible values of a variable

Is there a term to represent a set of all possible values a variable can assume?
Analogy:
In mathematics a domain of a function is a set of values a function is defined on (function can take as an argument).
Examples:
A variable of type UInt16 can hold values in range [0-65536).
Completion status (represented by a double value) can hold a value in range [0-100].
Gender (represented by an Enum) can hold one of { Male, Female }.
Q:
What is a term to describe all possible values a variable can (contextually) assume?
Basically need a short version of "set of values for a variable". I have seen term type being used to describe such a range, but Type often encompasses other bits of information (e.g. a name, operations, module).
value set
domain
value range
I've also heard "value space" as a term for this.
I would just call it the "range", or "range of values".
Domain would be the math term.
I don't know of programming-specific jargon with that meaning, but "domain" itself seems like a pretty good one...
[EDIT] Read the comments to this, and I actually prefer "range".
I don't know if this is the exact terminology (if it even has one) but I have always referred to it as a range or in the case of enums options.
Range is the proper term, as in "this method will return values within the range of..."; "The expected range of this variable is:..." etc.
For atomic types, the type itself describes the range (e.g. int has a range of -2,147,483,648 to 2,147,483,647).
Anything that is a custom type may or may not have a range because custom types (e.g. struct, class, interface) are composite types that can be made up of atomic or other custom types.
The definition of a type will also vary between different languages.
The long and short of it is generally you will only be able to apply a range to atomic types based on a specific language.
It depends on the type system. In some programming laguages, a "string" can hold a sequence of characters, and an "unsigned int" can only hold positive whole numbers. In others like python, a variable can hold anything at all because it doesn't have a certain type.
Our quants here say it is called a value set. They get paid tons of money to create them so I believe them!
You may think of a variable as containing an element that is a member of a set of numbers.
As such, domain is a good descriptor for the possible values of this set.
Range is also often used in a similar context. Here we talk of the range of a function, as the set of values the function can take on. Since a variable always contains the result of some expression or computation, range clearly makes sense too.
Either is appropriate in the proper context.