How to clone complete database in influxDB - influxdb

I am creating back up of measurement with in Db as shown below:
SELECT * INTO backdata FROM sourcedata
Above command created backdata measurement. Is there a way to clone complete DB with all measurement with different dbname?

First you'll need to create a new database
CREATE DATABASE mydb
Then the following query should work
SELECT * INTO mydb..:MEASUREMENT FROM /.*/ GROUP BY *

Related

Influxdb query on tag returns nothing

I have an Influxdb with lots of fields and a single tag:
> show tag keys
name: rtl433
tagKey
------
model
Now, I want a list of all possible values for model, so I run
SELECT model FROM rtl433
>
-and it returns nothing. Why? There's lots of data in model if I select *.
You are trying to use classic SQL solution, but InfluxDB is not classic SQL DB. You should check InfluxDB doc and you will find solution:
SHOW TAG VALUES WITH KEY = "model"

Informix SQL 11.5 storing multiple query results in one file

When I try to save the result of several queries in a file with an unload command in Dbaccess environment , only the first one is saved, and if I use unload several times -one time per query-, only the last query result is saved.
unload to file1
select * from table1;
select * from table2;
select * from table3;
Can anyone help?

How to create a measurement in InfluxDB

I am a beginner with InfluxDB and I've read the intro documentation, but cannot find any details on how to create a new measurement. Am I missing something ?
As noted in the comments, to "create" a new measurement you simply insert data into that measurement.
For example
$ influx
> CREATE DATABASE mydb
> USE mydb
Using database mydb
> SHOW MEASUREMENTS
> INSERT cpu,host=serverA value=10
> SHOW MEASUREMENTS
name: measurements
name
----
cpu
> INSERT mem,host=serverA value=10
> SHOW MEASUREMENTS
name: measurements
name
----
cpu
mem
In INFLUX DB , you cant create empty measurements.
You need to add some data as well.
For Example,
INSERT xyz,name=serverA value=10,count=10
This will create a measurement name xyz where
tag keys : name
field keys : value & count
You can check Field and tag keys by executing show field keys or show tag keys.
In the INSERT command, the format is like :
measurement_name,tag keys + value separated by comma Field keys with value separated by comma
eg: INSERT xyz,name=serverA value=10,count=10
In this way, you can create measurement with specifying your required field and tag keys.
You cannot create an empty measurement, afaik.
Like they said above, if you want one you need to start writing to it and that should take care of creating one along with some data in it.
insert load,app_name=app3,groupname=second,performance=degraded uuid=003,loading=50,frequency=1
In the above, we are using "insert" to write new data into a new measurement called "load".
app_name,groupname,performance are 'tags' and uuid,loading,frequency are fields
create database <data base name of your choice>
create user "<username>" with password '<password>'
To see the all databases: SHOW DATABASES
Enter the Database: use <database name>
To see all tables inside the database: SHOW MEASUREMENTS
grant all on <data base name> to <username>
insert data (Here Motionsense is a Measurement which is similar to the table name of SQL): INSERT MotionSense,SensorType=Gyro roll=1.2,yaw=5,pitch=3
See the data of the Measurements: SELECT * FROM "MotionSense"

Influxdb Move Copy data between databases within Influxdb

I have my_db1, my_db2, my_db3 in Influxdb, now is there a way to move or copy data between these databases with a query?
InfluxQL provides an INTO clause that can be used to copy data between databases.
For example, if I had the point cpu,host=server1 value=100 123 in db_1 and wanted to copy that data to the point new_cpu,host=server1 value=100 123 in db_2. I could issue the following query:
SELECT * INTO db_2..new_cpu FROM db_1..cpu group by *
For more information, see the documentation

How to use inner join inside the update query in SQLite in Objective C?

I want to update whole table from on query. Following is my update functionality is happened:
Database (Database A) stored in the iDevice
Temperory Database (Batabase B) downloads to the device and store in the temp folder inside the device. (Both DB has same database structure)
First I attach temp db to device database. Attached db name is SECOND1
Then I insert new records from temp db to device folder from following Insert code. It is working fine.
INSERT INTO main.fList SELECT * FROM SECOND1.fList WHERE not exists (SELECT 1 FROM main.fList WHERE main.fList.GUID = SECOND1.fList.GUID)
But when I use following code to update it is not working fine. It update same top value for all device db table's rows.
UPDATE fList SET Notes = (SELECT SECOND1.fList.Notes FROM SECOND1.fList WHERE SECOND1.fList.GUID = fDefectList.GUID) WHERE EXISTS (SELECT * FROM SECOND1.fList WHERE SECOND1.fList.GUID = fList.GUID
I found SQL query for bulk update. Following is the code,
UPDATE fTempRank7
SET
fTempRank7.int_key = fRank7.int_key,
fTempRank7.int_rank6 = fRank7.int_rank6,
fTempRank7.title = fRank7.title,
fTempRank7.sequence = fRank7.sequence,
fTempRank7.lastupdated = fRank7.lastupdated
FROM
fTempRank7 INNER JOIN fRank7 ON
fTempRank7.int_key = fRank7.int_key
But in sqlite this code does not work.
Anyone knows bulk update in sqlite?
SQLite does not support joins in an UPDATE statement.
When you use a table name without a database name, it refers to the first matching table in the innermost query. In other words, if you use SECOND1.fList in a subquery, any other occurrence of fList refers to the table in SECOND1.
To ensure that you always refer to the correct table, use the database name in all table references.
The main database is always named main, so all table references should be either main.fList or SECOND1.fList.
Anyway, if you are updating all columns, you can simplify the update by deleting the rows that would be updated, so that all new data can just be inserted:
BEGIN;
DELETE FROM fList WHERE GUID IN (SELECT GUID FROM SECOND1.fList);
INSERT INTO fList SELECT * FROM SECOND1.fList;
COMMIT;
When you have a UNIQUE constraint on the GUID column, this can be simplified into a single statement:
INSERT OR REPLACE INTO fList SELECT * FROM SECOND1.fList;
And here I don't use main. because I know what I'm doing. ☺

Resources