Floating points

You can use floating point numbers (numbers with a decimal point) in PQL to get fractional results, and display results with decimal places without changing the value.


Examples

You can try the following examples against your own data in the GoToManage search field, or against fictitious data in the Query Sandbox:


Example 1: Find free space as a fraction

You can use floating point numbers in PQL to get fractional results. For example, if you want to compute the percentage utilization of a disk, use the following query to get the free space as a fraction:

Query:

 SELECT freespace / size 
 FROM /network/device/wmi/win32_logicaldisk

Results: Depending on the database, this query returns results similar to this:

row
   freespace / size null
row
   freespace / size 0.0661251
row
   freespace / size 0.566196
row
   freespace / size 0.815274 
   . . .

Example 2: Find disk size as a fraction

You can display results with decimal places by convering them to floating point numbers, by simply adding a decimal to any number in a mathematical equation. The following query gets the disk size as a fraction:

Query:

 SELECT systemname, name, (size / 1073741824.0) 
 FROM /network/device/wmi/win32_logicaldisk 
 WHERE drivetype=3

Results: Depending on the database, this query returns results similar to this:

row
   systemname: SATURN
   name: D:
   size / 1.07374e+09: 465.713
row
   systemname: JUPITER
   name: C:
   size / 1.07374e+09: 70.8739
row
   systemname: MERCURY
   name: C:
   size / 1.07374e+09: 12.0038 
   . . .

Example 3: Find disk size in GBs

You can display results with decimal places without changing the value, by multiplying by 1.0. You can further customize the results using || in the query:

Query:

SELECT systemname, name, (size / 1073741824.0)||'GB' 
   as "Size GB" 
FROM /network/device/wmi/win32_logicaldisk 
WHERE drivetype=3

Results: Depending on the database, this query returns results similar to this:

row
   systemname: SATURN
   name: D:
   Size GB: 465.713 GB
row
   systemname: JUPITER
   name: C:
   Size GB: 70.8739 GB
row
   systemname: MERCURY
   name: C:
   Size GB: 12.0038 GB 
   . . .

Example 4: Make mathematical calculations

You can perform calculations in PQL, such as multiplication:

Query:

SELECT 2.3 * 4.3 FROM /

Results:

row
   9.89

If you use PQL for division, you must use spaces to avoid PQL interpreting the slash as a path. In the following example, 1 must be a floating point number:

Query:

SELECT 1.0 / 2 FROM /

Results:

row
   0.5

Another example:

Query:

SELECT 2.1 ** 2 FROM /

Results:

row
   4.41

You can calculate with hexidecimal numbers, too:

Query:

select 0x80 from /

Results:

row
   128

In this example, hexidecimal numbers are used with bitfields in configuring information. This query finds the disabled or enabled users on a network:

Query:

SELECT path 
FROM /directory/item 
WHERE properties/useraccountcontrol & 2 = 0 

Results:

row
   path: CN=Computers,CN=ELECTRON
row
   path: OU=Domain Controllers,CN=PROTON
row
   path: CN=Computers,CN=TOM-RAIMONDO
   . . .

To find disabled users, use 2=1. To find enabled users, use 2=0. You can look up useraccountcontrol of an individual, and use that to write a more specific query that tells you whether that individual's account is enabled or disabled.

 

Mac, iPad, and the Mac logo are trademarks of Apple, Inc. registered in the U.S. and other countries.