Linux/TimescaleDB: Difference between revisions

From Wiki
mNo edit summary
mNo edit summary
Line 1: Line 1:
== Setup ==
== Setup ==
<blockquote>
<pre>
<pre>
CREATE TABLE sensor_data (
CREATE TABLE sensor_data (
Line 7: Line 8:
);
);
</pre>
</pre>
</blockquote>


<blockquote>
<pre>
<pre>
SELECT create_hypertable('sensor_data', 'time');
SELECT create_hypertable('sensor_data', 'time');
</pre>
</pre>
</blockquote>


== Insert data via Node-RED ==
== Insert data via Node-RED ==
<blockquote>
<pre>
<pre>
INSERT INTO sensor_data (time, topic, value)
INSERT INTO sensor_data (time, topic, value)
Line 21: Line 26:
);
);
</pre>
</pre>
</blockquote>


== Get table size ==
== Get table size ==
<blockquote>
<pre>
<pre>
SELECT hypertable_size('sensor_data');
SELECT hypertable_size('sensor_data');
</pre>
</pre>
</blockquote>


[[Category:Linux/Services]]
[[Category:Linux/Services]]
[[Category:Linux]]
[[Category:Linux]]
[[Category:Programming]]
[[Category:Programming]]

Revision as of 15:34, 28 September 2024

Setup

CREATE TABLE sensor_data (
        time TIMESTAMPTZ NOT NULL,
        topic TEXT,
        value DOUBLE PRECISION
);
SELECT create_hypertable('sensor_data', 'time');

Insert data via Node-RED

INSERT INTO sensor_data (time, topic, value)
VALUES (
    now(),
    '{{{ msg.topic }}}',
    '{{{ msg.payload }}}'
);

Get table size

SELECT hypertable_size('sensor_data');