Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

PI SQL Client ODBC

Timestamp conditions

  • Last UpdatedJan 04, 2023
  • 2 minute read

An issue exists when querying tables and using a timestep condition. In the following example, the timestamp is specified without subseconds. Oracle parametrizes the timestep column using a Timestamp ODBC data type. This Timestamp contains dirty subseconds as shown by the trace file, which leads to an unexpected result. In the example query, the value timestamp returned is different than the one specified in the condition.

Examples:

-- The following PI SQL View is created using PI SQL Commander
CREATE VIEW [Master].[Element].[SampledValueView]
AS
SELECT "@time" time, sv."value", CAST("@time" AS "string") "time2", ea.Name "Name"
FROM [Master].[Element].[ft_GetSampledValue] sv
INNER JOIN [Master].[Element].[Attribute] ea ON ea.ID = sv.[@AttributeID]
WHERE ea.Element = 'B-210'

-- This query is executed using Oracle SQL Developer
SELECT "time" time1, "value" value, "time2" time2
FROM SampledValueView@pi
WHERE "Name" = 'Water Flow' AND "time" = '21-Apr-2019 12:30:00'

Result:

The trace file shows that subseconds are part of the timestamp parameter value being passed:

.
.
.
SQL text from hgopars, id=1, len=75 ...
00: 53454C45 43542022 74696D65 222C2276 [SELECT "time","v]
10: 616C7565 222C2274 696D6532 222C224E [alue","time2","N]
20: 616D6522 2046524F 4D202253 414D504C [ame" FROM "SAMPL]
30: 45445641 4C554556 49455722 20574845 [EDVALUEVIEW" WHE]
40: 52452022 74696D65 223D3F [RE "time"=?]
Exiting hgopars, rc=0 at 2019/05/13-16:05:15
Entered hgoopen, cursor id 1 at 2019/05/13-16:05:15
hgoopen, line 89: Printing hoada @ 000000C7E2DBEFD0
MAX:1, ACTUAL:1, BRC:1, WHT=3 (BIND_LIST)
DTY NULL-OK LEN MAXBUFLEN PR/SC CST IND MOD NAME
93 TIMESTAMP N 16 0 0/ 0 0 0 0 ?
Entered hgoprbv at 2019/05/13-16:05:16
hgoprbv, line 216: Printing hoada @ 000000C7E2DBEFD0
MAX:1, ACTUAL:1, BRC:1, WHT=3 (BIND_LIST)
DTY NULL-OK LEN MAXBUFLEN PR/SC CST IND MOD NAME
93 TIMESTAMP N 16 0 0/ 0 0 0 0 ?
Entered WP_SQLBindParameter at 2019/05/13-16:05:16
ParameterNumber 1, InputOutputType 1, ValueType 93, ParameterType 93,
ColumnSize 28, DecimalDigits 8, BufferLength 16,StrLen_or_IndPtr 0x000000C7E2DBEE90 (*0x10)
(Array size: 1)
16 bytes of data at 0x000000C7C9B14D50....
.
.

TitleResults for “How to create a CRG?”Also Available in