S
S
Sergey Fedotov2020-03-20 19:33:36
PHP
Sergey Fedotov, 2020-03-20 19:33:36

Storage of data from sensors. How to generate UUID?

The history of the issue. PostgreSQL base. The server flew on a raspberry where information from temperature sensors, humidity and others was stored. Somehow I pulled out a dump from a flash drive, but there was no data for half a month. Restored, flooded, launched. Then it turned out that I still backed up the data through Adminer and a large amount of data was saved (13 days out of 14+). I had to play around with Autoincrement, expand the range so that the desired section fits in, fill in the dump. And then an idea arose, since I can change the format of the base - change the autoincrement type ID to uuid based on the timestamp and device id. Has anyone solved a similar problem? Is there already a well-founded solution?
PS I'm not interested in the code any more, but in the theory of storing this type of data and using UUID. Everything in the context of the DBMS, specifically PostgreSQL.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Melkij, 2020-03-20
@melkij

What for? If you want to generate uuid on the base - just take sequence. There is no reason to use uuid in this case, and there will be nasty side effects.

I had to play with Autoincrement, move the range apart so that the desired section fits

What for?
We took the data and inserted the data by generating new sequences. sequence gives guaranteed unique values.

S
Seedor, 2020-03-20
@Seedor

Well, there are regular tools for this
https://postgrespro.ru/docs/postgresql/9.6/datatyp...
Take and use.)

M
mayton2019, 2020-03-21
@mayton2019

There is absolutely no motivation to use uuid.
Uuid is used in distributed messaging systems where it is fundamentally impossible to provide a single counter.
In the author's case, it's better to just work with arithmetic to load the necessary data without key conflicts. And save valuable space.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question