You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/basics/comparison.md
+77-18Lines changed: 77 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,39 +73,102 @@ q)(1 + 1e-13) = 1
73
73
74
74
## Temporal values
75
75
76
+
Below is a matrix of the [type](datatypes.md) used when the temporal types differ in a comparison (note: you may need to scroll to the right to view the full table):
q)20:00:00.000603286 within 13:30 20:00t / comparison of timespan and time, time converted to timespan values 0D13:30:00.000000000 0D20:00:00.000000000
92
+
0b
93
+
q)2024.10.07D20:00:00.000603286 within 13:30 20:00t / comparison of timestamp and time, timestamp converted to time value 20:00:00.000
94
+
1b
95
+
```
96
+
76
97
Particularly notice the comparison of ordinal with cardinal datatypes, such as timestamps with minutes.
When comparing ordinals with cardinals, ordinal is converted to the cardinal type first: `stamps=t` is equivalent to ``(`minute$stamps)=t`` and thus
109
+
When comparing `timestamp` with `minute`, the timestamps are converted to minutes such that `` `minute$2024.11.01D09:29:15.000000000 ``becomes `09:29`and therefore doesn't appear in the output:
86
110
87
111
```q
88
-
q)(stamps<t;stamps=t;stamps>t)
89
-
100000b
112
+
q)select from tab where timeStamp>09:29 / comparing timestamp with minute
When comparing `timespan` with `minute`, the minute is converted to timespan such that `09:29` becomes `0D09:29:00.000000000` for the following comparison:
120
+
121
+
```q
122
+
q)select from tab where timeSpan>09:29 / comparing timespan with minute
Precision of floats is a tricky issue since floats (_doubles_ in other languages) are actually binary rational approximations to real numbers. Whenever you are concerned with precision, set `\P 0` before doing anything else, so that you can see what’s really going on.
13
+
Precision of floats is a complex issue because floats (known as _doubles_ in other programming languages) are actually binary rational approximations of real numbers. If you are concerned with precision, make sure to set [`\P 0`](syscmds.md#p-precision) before proceeding with anything else. This helps you understand what's really happening with your data.
14
14
15
15
Due to the finite accuracy of the binary representation of floating-point numbers, the last decimal digit of a float is not reliable. This is not peculiar to kdb+.
16
16
@@ -22,7 +22,7 @@ q)1%3
22
22
23
23
Efficient algorithms for complex calculations such as log and sine introduce imprecision. Moreover, even basic calculations raise issues of rounding. The IEEE floating-point spec addresses many such issues, but the topic is complex.
24
24
25
-
Q takes this into account in its implementation of the equality operator `=`, which should actually be read as “tolerantly equal.” Roughly speaking, this means that the difference is relatively small compared to some acceptable representation error. This makes the following hold:
25
+
Q takes this into account in its implementation of the equality operator [`=`](comparison.md), which should actually be read as “tolerantly equal.” Roughly speaking, this means that the difference is relatively small compared to some acceptable representation error. This makes the following hold:
26
26
27
27
```q
28
28
q)r7:1%7
@@ -102,7 +102,7 @@ The l64 builds of kdb+ now have a faster SIMD [`sum`](../ref/sum.md) implementat
102
102
103
103
Consider the task of calculating the sum of `1e-10*til 10000000`.
104
104
105
-
The SIMD code is equivalent to the following (`\P 0`):
105
+
The SIMD code is equivalent to the following ([`\P 0`](syscmds.md#p-precision)):
106
106
107
107
```q
108
108
q){x+y}over{x+y}over 0N 8#1e-10*til 10000000
@@ -280,4 +280,4 @@ These do not use comparison tolerance, and are therefore appropriate for databas
This loads the entire database, which may consist of several tables. Use `.odbc.tables` to list the tables.
19
+
!!! note "The name of the driver may differ between versions. The command above should be altered to reflect the driver name installed."
20
+
21
+
Use [`.odbc.tables`](../interfaces/q-client-for-odbc.md#tables) to list the tables.
21
22
22
23
```q
23
24
q).odbc.tables h
24
25
`aa`bb`cc`dd`ii`nn
25
26
```
26
27
27
-
Use `.odbc.eval` to evaluate SQL commands via ODBC.
28
+
Use [`.odbc.eval`](../interfaces/q-client-for-odbc.md#eval) to evaluate SQL commands via ODBC.
28
29
29
30
```q
30
31
q).odbc.eval[h;"select * from aa"]
31
32
```
32
33
33
-
---
34
-
:fontawesome-solid-handshake:
35
-
[Q driver for ODBC3](../interfaces/q-server-for-odbc3.md)
34
+
An alternative to querying through SQL is to load the entire database into kdb+ via the [.odbc.load](../interfaces/q-client-for-odbc.md#load) command, where the data can then be queried using kdb+ directly.
0 commit comments