-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: how to get the last sample records in one step #44
Comments
Hi @cobolbaby ,
Last function has 3 ways to use follow https://docs.influxdata.com/influxdb/v1/query_language/functions/#last.
|
The default UDFs might not meet the requirements; they either fail to retrieve results or return text data that looks like tuples. Could you give me some suggestions? bdc=# \d dm.iot_sqt_agv_count;
Foreign table "dm.iot_sqt_agv_count"
Column | Type | Collation | Nullable | Default | FDW options
----------+--------------------------+-----------+----------+---------+-------------
time | timestamp with time zone | | | |
agvState | character varying | | | |
value | numeric | | | |
Server: influxdb_iot
FDW options: ("table" 'F3AGV.count', tags 'agvState,value', schemaless 'true')
bdc=# select * from dm.iot_sqt_agv_count order by time desc limit 10;
time | agvState | value
----------------------------+------------+-------
2024-05-20 18:15:55.562+08 | onlineAGV | 88
2024-05-20 18:15:55.562+08 | LOCKED | 11
2024-05-20 18:15:55.562+08 | IDLE | 5
2024-05-20 18:15:55.562+08 | offlineAGV | 3
2024-05-20 18:15:55.562+08 | BUSY | 70
2024-05-20 18:15:55.562+08 | totalAGV | 91
2024-05-20 18:15:55.562+08 | CHARGING | 1
2024-05-20 18:15:55.562+08 | ERROR | 1
2024-05-20 18:14:55.572+08 | totalAGV | 91
2024-05-20 18:14:55.572+08 | BUSY | 71
(10 rows)
bdc=# select last(time, "agvState") from dm.iot_sqt_agv_count;
last
------
(0 rows)
bdc=# select last(time, value) from dm.iot_sqt_agv_count;
ERROR: stub last_sfunc(anyelement, timestamp with time zone, anyelement) is called
CONTEXT: PL/pgSQL function last_sfunc(anyelement,timestamp with time zone,anyelement) line 3 at RAISE
bdc=# select last_all(*) from dm.iot_sqt_agv_count;
last_all
-----------------------------------------------------
(2024-05-20T10:16:55.548Z,,"{\"value\" : \"91\" }")
(1 row)
bdc=# select last('/value/') from dm.iot_sqt_agv_count;
last
-----------------------------------------------------
(2024-05-20T10:16:55.548Z,,"{\"value\" : \"91\" }")
(1 row)
bdc=# select max(time) from dm.iot_sqt_agv_count where time > now() - interval '1 hour';
max
----------------------------
2024-05-20 18:17:55.564+08
(1 row)
bdc=# select * from dm.iot_sqt_agv_count where time = '2024-05-20 18:17:55.564+08';
time | agvState | value
----------------------------+------------+-------
2024-05-20 18:17:55.564+08 | BUSY | 70
2024-05-20 18:17:55.564+08 | CHARGING | 1
2024-05-20 18:17:55.564+08 | ERROR | 1
2024-05-20 18:17:55.564+08 | IDLE | 7
2024-05-20 18:17:55.564+08 | LOCKED | 10
2024-05-20 18:17:55.564+08 | offlineAGV | 2
2024-05-20 18:17:55.564+08 | onlineAGV | 89
2024-05-20 18:17:55.564+08 | totalAGV | 91
(8 rows) |
Hello @cobolbaby
The last() function cannot work because the last() function only works for key fields. https://docs.influxdata.com/influxdb/v1/query_language/functions/#last |
How to convert the text |
Can you try |
ERROR: invalid input syntax for type numeric: "{"value" : "91" }" SQL state: 22P02 |
Thank you for feedback. But I would like to know your table schema is correct?
The schemaless mode is enabled. But your column is |
You're right, I didn't notice the option. It seems there were no errors with ALTER FOREIGN TABLE IF EXISTS dm.iot_sqt_agv_count
OPTIONS (SET schemaless 'false');
select (last_all(*)::dm.iot_sqt_agv_count).* from dm.iot_sqt_agv_count;
ERROR: Too many columns.malformed record literal: "(2024-08-05T04:38:22.974Z,,,)"
ERROR: malformed record literal: "(2024-08-05T04:38:22.974Z,,,)"
SQL state: 22P02
Detail: Too many columns.
select * from dm.iot_sqt_agv_count order by time desc limit 10;
"2024-08-05 12:46:23.022+08" "onlineAGV" 88
"2024-08-05 12:46:23.022+08" "LOCKED" 12
"2024-08-05 12:46:23.022+08" "IDLE" 18
"2024-08-05 12:46:23.022+08" "offlineAGV" 3
"2024-08-05 12:46:23.022+08" "BUSY" 52
"2024-08-05 12:46:23.022+08" "totalAGV" 91
"2024-08-05 12:46:23.022+08" "CHARGING" 6
"2024-08-05 12:46:23.022+08" "ERROR" 0
"2024-08-05 12:45:22.997+08" "totalAGV" 91
"2024-08-05 12:45:22.997+08" "BUSY" 50 |
It looks like your remote table (table on Influxdb) has more columns than 3 (time, avgState, value).
is it correct? |
Yes. |
To expose it, it must be able to cast the record to a table data type where the data type matches the value (including number of columns, and data type of each column).
|
@cobolbaby , is the problem resolved after last release? |
How to quickly retrieve the latest sampling records? Currently, my approach is to use a query similar to the following:
How to use the
last
function in the README?The text was updated successfully, but these errors were encountered: