INSERT - GoToAssist Monitoring

Find an Answer

Search GoToAssist Monitoring articles, videos and user guides   Your search term must have 2 or more characters.

INSERT

Syntax

Use INSERT statements to add data to the database. The possible elements of a INSERT statement include:

            pql_statement 	::= 	INSERT [INTO] path
                        VALUES tree_literal
		
tree_literal    ::=     {tree_assignment [, tree_assignment]}
        
            tree_assignment ::= 	identifier => expression | identifier => tree_literal
 
        

Description

The elements of a INSERT statement are defined as follows:

INSERT
[INTO]
 Adds data to the database at the location indicated by the node path. The INTO keyword is optional.
  The path is required. The path indicates the location of the anchor-point node. A path can be represented by an identifier or a boolean expression.
VALUES  Indicates the new values to be added to the database. The VALUES statement must include a tree_literal expression.

 

Examples

You can try the following examples yourself against fictitious data in the Query Sandbox:

Example 1: Insert a device with interfaces

Suppose you want to add a device with two interfaces. Write an INSERT statement using a simple, "insert a into b" format like this:

                                     INSERT INTO / VALUES {
    a => 'b'
  } 
                                    

You need the keywords INSERT INTO to add new data without overwriting existing data, followed by a / slash to represent the root node where the new values will be added. Next, the keyword VALUES, followed by the actual values to be added. The => equal-to-or-greater-than symbol indicates where to insert new data:

            INSERT INTO / VALUES {
   device => {
     name => 'KRONOS', 
     interface => {
       mac_address => 'A1:A2:A3:A4:A5:A6'
     }, 
     interface => {
       mac_address => 'B1:B2:B3:B4:B5:B6'
     }
   }
 } 


        

This statement produces a result like this:

            row
  *
   device
    interface
     mac_address A1:A2:A3:A4:A5:A6                                             
    interface
     mac_address B1:B2:B3:B4:B5:B6
    name KRONOS


        

Example 2: Insert more data

Expand the basic INSERT statement to include more information such as interface names, MAC addresses, OS and system data, and so on. This example inserts two devices, a workstation and a router:

            INSERT INTO / values {
  network => {
    device => {
      system => {
        name => 'KRYPTON', 
        computed_model => 'Windows Workstation', 
        computed_class => 'workstation', 
        computed_score => '125'
      }, 
      os => {
        version => 'Darwin Kernel Version 9.2.2' 
      }, 
      interface => {
        name => 'eth0', 
        mac_address => '08:16:CB:FF:FE:66', 
        in_octets => '0',
        out_octets => '346',
        oper_status => '1'
      } 
    },
    device => {
      system => {
        name => 'NISSINGETTY',
        computed_vendor => 'Juniper Networks', 
        computed_model => 'Netscreen Router', 
        computed_class => 'router', 
        computed_score => '60'
      }, 
      os => {
        version => 'NetScreen-5GT 5.1.043a' 
      }, 
      interface => {
        name => 'eth0', 
        mac_address => '12:10:D8:99:2B:C2', 
        in_octets => '1385354750',
        out_octets => '1451321493',
        oper_status => '1'
      }, 
      interface => {
        name => 'eth1', 
        mac_address => '13:10:D8:99:2B:C1', 
        in_octets => '3312952833',
        out_octets => '3239791359',
        oper_status => '1'
      }
    }
  }
}


        

This statement produces a result like this:

            row
  *
    network
      device
        interface
          mac_address 08:16:CB:FF:FE:66
          name eth0
          in_octets 0
          out_octets 346
          oper_status 1
        system
          name KRYPTON
          computed_model Windows Workstation
          computed_class workstation
          computed_score 125
        os
          version Darwin Kernel Version 9.2.2
      device
        interface
          mac_address 12:10:D8:99:2B:C2
          name eth0
          in_octets 1385354750
          out_octets 1451321493
          oper_status 1
        interface
          mac_address 13:10:D8:99:2B:C1
          name eth1
          in_octets 3312952833
          out_octets 3239791359
          oper_status 1
        system
          name NISSINGETTY
          computed_vendor Juniper Networks
          computed_model Netscreen Router
          computed_class router
          computed_score 60
        os
          version NetScreen-5GT 5.1.043a


        

Note: Specify the node

You must specify the exact node that the new sub-tree grafts from. In the following examples, the first statement works, but the second is not specific enough:

This statement works because it inserts values into a specific node:

            INSERT INTO /device[name = 
      'my_device']/interface[mac_address 
      = '00:01:02:03:04:05'] values...


        

This statement doesn't work because it attempts to insert values into a non-leaf node:

            INSERT INTO /device/interface values...


        

For more examples, see Examples and More examples.

Related topics

Did this article answer your question?
Yes
No
Why?