Moving on to the InfluxDB curd, first let’s look at how to add data, i.e. insert position
For those who do not know what retention policy, tag, and field are, it is necessary to go over these basic concepts quickly before this part, for reference in the subsequent series of tutorials
I. Insert Instructions
The basic grammar
insert into <retention policy> measurement,tagKey=tagValue fieldKey=fieldValue timestamp
Copy the code
1. Basic data write posture
This measurement is created when we insert a piece of data when it does not exist
A. basic case
A simple example is given below
insert add_test,name=YiHui,phone=110 user_id=20,email="[email protected]"
- Add a data item at measurement is
add_test
The tag forname
.phone
The field foruser_id
.email
> show measurements
name: measurements
name
----
yhh
> insert add_test,name=YiHui,phone=110 user_id=20,email="[email protected]"> show measurements; name: measurements name ---- add_test yhh > select * from add_test name: add_test time email name phone user_id ---- ----- ---- ----- ------- 1564149327925320596 [email protected] YiHui 110 20 > show tag keys from add_test; name: add_test tagKey ------ name phone > show field keys from add_test; name: add_test fieldKey fieldType -------- --------- email string user_idfloat
Copy the code
From the output above, briefly summarize the insertion statement
insert
+measurement
+","
+tag=value,tag=value
++
field=value,field=value
- Tags are separated by commas (,). Fields are separated by commas
- Tags and fields are separated by Spaces
- Tags are strings and do not need quotation marks to enclose values
- Field If it is a string, quotation marks are required
B. the field type
Int, float, string, Boolean, float, float, float, float, float, float, float
> insert add_test,name=YiHui,phone=110 user_id=21,email="[email protected]",age=18i,boy=true
> show field keys from add_test
name: add_test
fieldKey fieldType
-------- ---------
age integer
boy boolean
email string
user_id float
Copy the code
Summarize the four types of designation
type | way | The sample |
---|---|---|
float | digital |
user_id=21 |
int | Digital I |
age=18i |
boolean | true/false |
boy=true |
String | "" or ' ' |
email=”[email protected]” |
C. Specify the timestamp
If no time is specified for data writing, the system automatically uses the current time to complete data writing. If you need to specify the time by yourself, you can add the time at the end. Note that the time is NS
> insert add_test,name=YiHui,phone=110 user_id=22,email="[email protected]",age=18i,boy=true 1564150279123000000
> select * from add_test;
name: add_test
time age boy email name phone user_id
---- --- --- ----- ---- ----- -------
1564149327925320596 [email protected] YiHui 110 20
1564149920283253824 18 true [email protected] YiHui 110 21
1564150279123000000 18 true [email protected] YiHui 110 22
Copy the code
2. Specify a save policy to insert data
If no save policy is specified for data written before, the data is written to the default save policy. We can use insert into to save data in a measurement file. When a measurement file is used to save data in a measurement file, we can use insert into to save data in a measurement file.
> show retention policies on test
name duration shardGroupDuration replicaN default
---- -------- ------------------ -------- -------
autogen 0s 168h0m0s 1 true
1_d 24h0m0s 1h0m0s 1 false
1_h 1h0m0s 1h0m0s 1 false
> insert into "1_d" add_test,name=YiHui2,phone=911 user_id=23,email="[email protected]",age=18i,boy=true 1564150279123000000
> select * from add_test;
name: add_test
time age boy email name phone user_id
---- --- --- ----- ---- ----- -------
1564149327925320596 [email protected] YiHui 110 20
1564149920283253824 18 true [email protected] YiHui 110 21
1564150279123000000 18 true [email protected] YiHui 110 22
> select * from "1_d".add_test;
name: add_test
time age boy email name phone user_id
---- --- --- ----- ---- ----- -------
1564150279123000000 18 true [email protected] YiHui2 911 23
Copy the code
II. The other
0. Series of blog posts
- 190723- Whole ARRAY Sql Series 4: Series/Point/Tag/Field
- 190721- Whole Sql Series 3: Measurement Tables
- 190719- Readership RETENTION Policies, Readership Retention Policies, Readership Retention Policies, Readership Retention Policies
- 190718- Whole Sql Series 1: Database database
- 190717- Introduction to Installation and READy-to-USE CLI posture
- 190509-InfluxDb Timestamp is displayed in date format
- 190506-InfluxDB Configuration modified
- 190505-Rights management for the InfluxDB
- 180727- Backup and restore policies for the sequential database InfluxDB
- Summary of basic concepts of 180726-InfluxDB
- Installation and Simple use summary of 180725-INFLUxDB-V1.6.0
Refer to the post
- Docs.influxdata.com/influxdb/v1…
- Docs.influxdata.com/influxdb/v1…
- docs.influxdata.com/influxdb/v1.7/tools/shell/#write-data-to-influxdb-with-insert
1. A gray Blog:liuyueyi.github.io/hexblog
A gray personal blog, recording all the study and work in the blog, welcome everyone to go to stroll
2. Statement
As far as the letter is not as good as, has been the content, purely one’s own words, because of the limited personal ability, it is hard to avoid omissions and mistakes, such as finding bugs or better suggestions, welcome criticism and correction, not grudging gratitude
- Micro Blog address: Small Gray Blog
- QQ: a gray /3302797840
3. Scan attention
A gray blog