← instr operator page · string/instr/comp_pattern/manual_ex_3
pandas ✅ · DuckDB ✅
two instr calls in one calc on DS_2, where Me_1 is null in one data point.
String pattern location, Example 3, output verbatim: "If the nth occurrence of the string-pattern after the start th character is not found in the input string, the returned value is 0."
Me_10 is 5 and null, and Me_20 is 2 and 0: hi has no o, so its position is 0, while the null Me_1 gives null. A null operand gives a null result: "most of the scalar operations (arithmetic, logical, and others) return null when any of their arguments is null" (User Manual).
DS_r := DS_2 [calc Me_10:= instr(Me_1, "o" ), Me_20:=instr(Me_2, "o")];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 1 | A | hello | world |
| 2 | B | hi |
{
"datasets": [
{
"name": "DS_2",
"DataStructure": [
{"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
{"name": "Id_2", "type": "String", "role": "Identifier", "nullable": false},
{"name": "Me_1", "type": "String", "role": "Measure", "nullable": true},
{"name": "Me_2", "type": "String", "role": "Measure", "nullable": true}
]
}
]
}
| Id_1 | Id_2 | Me_1 | Me_2 | Me_10 | Me_20 |
|---|---|---|---|---|---|
| 1 | A | hello | world | 5 | 2 |
| 2 | B | hi | 0 |
{
"datasets": [
{
"name": "DS_r",
"DataStructure": [
{"name": "Id_1", "type": "Integer", "role": "Identifier"},
{"name": "Id_2", "type": "String", "role": "Identifier"},
{"name": "Me_1", "type": "String", "role": "Measure"},
{"name": "Me_2", "type": "String", "role": "Measure"},
{"name": "Me_10", "type": "Integer", "role": "Measure"},
{"name": "Me_20", "type": "Integer", "role": "Measure"}
]
}
]
}