Help Center/ GeminiDB/ GeminiDB Influx API/ Best Practices/ Basic Syntax Examples of GeminiDB Influx Instances
Updated on 2025-07-29 GMT+08:00

Basic Syntax Examples of GeminiDB Influx Instances

This section describes the basic syntax of GeminiDB Influx instances.

  • Database syntax
    • Create a database.

      create_database_stmt = "CREATE DATABASE" db_name

      [ WITH

      [ retention_policy_duration ]

      [ retention_policy_replication ]

      [ retention_policy_shard_group_duration ]

      [ retention_policy_name ]

      ] .

      The commands in square brackets ([]) are optional.

      Example:

      • Create a database named mydb.

        CREATE DATABASE "mydb"

      • Create a database named mydb using the specified retention policy myrp. Set the retention period to 1 day, the number of copies to 1, and the storage duration of shardGroup to 30 minutes.

        CREATE DATABASE "mydb" WITH DURATION 1d REPLICATION 1 SHARD DURATION 30m NAME "myrp"

      • Create a database named mydb using the default retention policy myrp.

        CREATE DATABASE "mydb" WITH NAME "myrp"

    • Query databases.

      SHOW DATABASES

    • Switch to another database.

      USE db_name

    • Delete a database.

      DROP DATABASE "db_name"

  • RETENTION POLICY
    • Create a retention policy and ensure that the policy name does not contain periods (,), colons (:), semicolons (;), or dots (.).

      create_retention_policy_stmt = "CREATE RETENTION POLICY" policy_name on_clause

      retention_policy_duration

      retention_policy_replication

      [ retention_policy_shard_group_duration ]

      [ "DEFAULT" ] .

      The commands in square brackets ([]) are optional.

      Example:

      • Create a data retention policy.

        CREATE RETENTION POLICY "10m_events" ON "somedb" DURATION 60m REPLICATION 2

      • Create a data retention policy and set it as the default one.

        CREATE RETENTION POLICY "10m_events" ON "somedb" DURATION 60m REPLICATION 2 DEFAULT

      • Create a data retention policy and specify the storage duration of shardGroup.

        CREATE RETENTION POLICY "10m_events" ON "somedb" DURATION 60m REPLICATION 2 SHARD DURATION 30m

    • View a retention policy.

      show retention policies on <database name>

      If you specify both parameters retention_policy_duration and retention_policy_shard_group_duration, ensure that the former parameter has a larger value than the latter.

    • Delete a retention policy.

      DROP RETENTION POLICY policy_name ON db_name

    • Modify a retention policy.

      Alter_retention_policy_stmt = "ALTER RETENTION POLICY" policy_name on_clause

      retention_policy_option

      [ retention_policy_option ]

      [ retention_policy_option ]

      [ retention_policy_option ] .

      The commands in square brackets ([]) are optional.

      Example:

      • Modify the default retention policy.

        ALTER RETENTION POLICY "1h_cpu" ON "mydb" DEFAULT

      • Modify the retention period and number of copies.

        ALTER RETENTION POLICY "policy1" ON "somedb" DURATION 1h REPLICATION 4

  • Add data.

    insert into <retention policy> measurement,tagKey=tagValue fieldKey=fieldValue timestamp

    When data is inserted, the system creates a measurement as required.

    • Use the default retention policy.

      insert demo,name=LiSi math=99,english=90,language=95

      Add data. Set measurement to demo, tag to name, and field to math, english, and language.

    • Use the specified retention policy.

      insert into rp_1_hours demo,name=ZhangSan math=99,english=90,language=95

  • Query data.
    • Query data from the default retention policy.

      select * from demo where time < xxx and time > xxx

    • Query data from the specified retention policy.

      select * from rp_1_hours.demo where time < xxx and time > xxx

      Specify a time range in the query statement.

  • Modify data.

    When you modify data using INSERT, if all tags and timestamps are the same, the existing data will be overwritten.

  • Delete data.

    You can create a retention policy to automatically delete data.

  • HELP command
    • Run HELP to view all supported commands.
      Figure 1 Viewing all supported commands
    • Run HELP <COMMAND> to query the usage of a command.

      Example: HELP DESC