Units
Convert measurements between units, normalize them to SI, and check that two quantities are comparable
- Connector software
- Free and open source
- Service credentials
- Not needed
- Query Farm hosting
- Available · $10/month organization minimum
Use with an agent
Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.
npx skills add Query-farm/vgi-skills --skill orchard
Copy this request into your coding agent to get started.
Use https://query.farm/products/orchard/connectors/units/index.md to help me query Units with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.
Normalize measurements to consistent units
Example output · captured
- Connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
WITH r AS (SELECT txt, units.main.parse_quantity(txt) AS q FROM (VALUES ('5 km'), ('2 GiB'), ('1 kWh'), ('98.6 °F')) AS t(txt)) SELECT r.txt, units.main.to_base((r.q).value, (r.q).unit) AS base_value, s.base_unit
FROM r
JOIN units.main.supported_units AS s ON s.unit = (r.q).unit
ORDER BY r.txt
| txt | base_value | base_unit |
|---|---|---|
| 1 kWh | 3,600,000 | J |
| 2 GiB | 2,147,483,648 | byte |
| 5 km | 5000 | m |
| 98.6 °F | 310.15 | K |
Quick start
Choose where to run Units, then follow the steps below.
The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.
1. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
2. Attach the connector
Attach the release directly
Downloads the latest release for your platform and caches it locally.
ATTACH 'units' AS units (
TYPE vgi,
LOCATION 'github-auto://Query-farm/vgi-units'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'units' AS units (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-units:0.5.0'
);
3. Run a query
WITH r AS (SELECT txt, units.main.parse_quantity(txt) AS q FROM (VALUES ('5 km'), ('2 GiB'), ('1 kWh'), ('98.6 °F')) AS t(txt)) SELECT r.txt, units.main.to_base((r.q).value, (r.q).unit) AS base_value, s.base_unit
FROM r
JOIN units.main.supported_units AS s ON s.unit = (r.q).unit
ORDER BY r.txt
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'units' AS units
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
WITH r AS (SELECT txt, units.main.parse_quantity(txt) AS q FROM (VALUES ('5 km'), ('2 GiB'), ('1 kWh'), ('98.6 °F')) AS t(txt)) SELECT r.txt, units.main.to_base((r.q).value, (r.q).unit) AS base_value, s.base_unit
FROM r
JOIN units.main.supported_units AS s ON s.unit = (r.q).unit
ORDER BY r.txt
Query Farm operates Units for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use units as the catalog alias for the query below.
4. Run a query
WITH r AS (SELECT txt, units.main.parse_quantity(txt) AS q FROM (VALUES ('5 km'), ('2 GiB'), ('1 kWh'), ('98.6 °F')) AS t(txt)) SELECT r.txt, units.main.to_base((r.q).value, (r.q).unit) AS base_value, s.base_unit
FROM r
JOIN units.main.supported_units AS s ON s.unit = (r.q).unit
ORDER BY r.txt
Technical details
- Verified connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
Pin a version for production
When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.
Attach the release directly
Uses the verified release each time you attach the connector.
ATTACH 'units' AS units (
TYPE vgi,
LOCATION 'github-auto://Query-farm/[email protected]'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'units' AS units (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-units:0.5.0'
);
Overview
Runtime, string-driven physical-unit conversion and dimensional analysis.
Convert physical quantities between units and run dimensional analysis directly in DuckDB SQL — length, mass, time, energy, temperature, pressure, data sizes, and more, all resolved at query time. The units worker brings runtime, string-driven unit conversion to your queries: units are named by ordinary strings ('mi', 'GiB', '°C', 'kWh'), so you can normalize measurements, check that two quantities are comparable, and reduce values to their SI base unit without leaving SQL.
This extension is for data engineers, analysts, and scientists who deal with messy, mixed-unit measurement data — energy bills in kWh, distances in miles and kilometers, storage in GiB and GB, sensor readings in mixed temperature scales. Instead of hard-coding conversion factors into every query or pipeline, you call a single well-tested function and get consistent, documented results. Because unit names are plain strings evaluated per row, it works naturally over columns of dirty real-world data, returning NULL for unrecognized units rather than aborting a scan.
Under the hood the worker is powered by a curated internal unit table rather than an external dependency: each unit string maps to a (dimension, factor, offset) triple, and every conversion is an exact affine round-trip through the SI base unit of its dimension (base = value * factor + offset). Offsets are used only by the temperature scales (°C/°F/K/°R) so that 0 °C = 273.15 K = 32 °F comes out right; all other factors are the exact agreed SI constants (e.g. inch = 0.0254 m, pound = 0.45359237 kg, atm = 101325 Pa, calorie = 4.184 J, IEC binary prefixes as 1024ⁿ vs decimal 1000ⁿ). The factors follow the official SI definitions maintained by the BIPM and the NIST reference on constants, units, and uncertainty.
When to reach for it. Use this worker whenever a query must reconcile measurements recorded in different units, confirm that two quantities are even comparable before combining them, reduce heterogeneous values to a common SI base so they can be aggregated, or turn free-text quantity strings into structured numeric values. It fits reporting pipelines that mix imperial and metric sources, scientific workloads that must normalize before doing math, and data-cleaning steps that quarantine unrecognized units as NULL rather than failing.
Catalog
Everything units exposes once attached — read straight from the worker's
released build.
main 2 tables · 7 functions
Unit-conversion and dimensional-analysis functions.
Schema examples (12)
Convert a marathon distance from miles to kilometres.
SELECT units.main.convert(26.2, 'mi', 'km') AS km;
Reduce 1 GiB to bytes via the SI base unit.
SELECT units.main.to_base(1, 'GiB') AS bytes;
Look up the physical dimension of a unit.
SELECT units.main.dimension('kWh') AS dim;
Check whether two units can be converted between.
SELECT units.main.compatible('mi', 'km') AS ok;
8 more examples
Parse a free-text quantity string into a (value, unit) struct.
SELECT units.main.parse_quantity('5 km') AS q;
List the recognized units in the length dimension.
SELECT unit, base_unit
FROM units.main.supported_units
WHERE dimension = 'length'
ORDER BY unit;
Parse free-text readings, group them by physical dimension, and total each group in its SI base unit; '7 furlongs' is not a recognized unit, so it parses to NULL and is skipped.
WITH r AS (SELECT units.main.parse_quantity(txt) AS q FROM (VALUES ('5 km'), ('3 mi'), ('800 m'), ('2 kg'), ('12 lb'), ('7 furlongs')) AS t(txt)) SELECT units.main.dimension((q).unit) AS dim, count(*) AS readings, round(sum(units.main.to_base((q).value, (q).unit)), 4) AS total_si
FROM r
WHERE q IS NOT NULL
GROUP BY dim
ORDER BY dim;
Normalize mixed free-text readings to SI and label each with its base unit by joining the parsed unit to supported_units (e.g. '98.6 °F' becomes 310.15 K).
WITH r AS (SELECT txt, units.main.parse_quantity(txt) AS q FROM (VALUES ('5 km'), ('2 GiB'), ('1 kWh'), ('98.6 °F')) AS t(txt)) SELECT r.txt, units.main.to_base((r.q).value, (r.q).unit) AS base_value, s.base_unit
FROM r
JOIN units.main.supported_units AS s ON s.unit = (r.q).unit
ORDER BY r.txt;
| txt | base_value | base_unit |
|---|---|---|
| 1 kWh | 3,600,000 | J |
| 2 GiB | 2,147,483,648 | byte |
| 5 km | 5000 | m |
| 98.6 °F | 310.15 | K |
Express one mile in every length unit the worker recognizes, largest number first.
SELECT unit, units.main.convert(1, 'mi', unit) AS one_mile
FROM units.main.supported_units
WHERE dimension = 'length'
ORDER BY one_mile DESC, unit;
Guard a conversion: convert each row to kilograms only when its unit is compatible with kg, so the length row ('m') yields NULL instead of an incompatible-dimension error.
SELECT id, qty, unit,
CASE WHEN units.main.compatible(unit, 'kg') THEN units.main.convert(qty, unit, 'kg') END AS kg
FROM (VALUES (1, 150.0, 'lb'), (2, 2.5, 'kg'), (3, 3.0, 'm'), (4, 16.0, 'oz')) AS t(id, qty, unit)
ORDER BY id;
Report each reactor's final temperature in °F with convert_strict and its rise in °F with convert_difference_strict: the 15 °C rise of reactor_a is 27 °F, not the 59 °F an absolute conversion would give.
SELECT sensor,
round(units.main.convert_strict(end_c, '°C', '°F'), 2) AS end_f,
round(units.main.convert_difference_strict(end_c - start_c, '°C', '°F'), 2) AS rise_f
FROM (VALUES ('reactor_a', 20.0, 35.0), ('reactor_b', 18.5, 21.0)) AS t(sensor, start_c, end_c)
ORDER BY sensor;
Audit strict temperature conversions: convert 100 of each unit with convert_strict and recompute the same result from the factor and offset published in unit_catalog ((value * f.factor + f.offset - t.offset) / t.factor).
SELECT f.unit AS from_unit, t.unit AS to_unit,
round(units.main.convert_strict(100, f.unit, t.unit), 6) AS converted,
round((100 * f.factor + f."offset" - t."offset") / t.factor, 6) AS recomputed
FROM units.main.unit_catalog AS f
JOIN units.main.unit_catalog AS t ON t.dimension = f.dimension AND t.unit <> f.unit
WHERE f.unit IN ('°C', '°F', 'K') AND t.unit IN ('°C', '°F', 'K')
ORDER BY from_unit, to_unit;
supported_units
Every unit string the worker recognizes, with its physical dimension and SI base unit.
List the length units and their SI base unit.
SELECT unit, base_unit
FROM units.main.supported_units
WHERE dimension = 'length'
ORDER BY unit;
Count how many units exist in each dimension.
SELECT dimension, count(*) AS n
FROM units.main.supported_units
GROUP BY dimension
ORDER BY n DESC, dimension;
Express one mile in every length unit the worker recognizes, largest number first.
SELECT unit, units.main.convert(1, 'mi', unit) AS one_mile
FROM units.main.supported_units
WHERE dimension = 'length'
ORDER BY one_mile DESC, unit;
6 more examples
SELECT units.main.convert(26.2, 'mi', 'km') AS km;
SELECT units.main.to_base(1, 'GiB') AS bytes;
SELECT units.main.dimension('kWh') AS dim;
SELECT units.main.compatible('mi', 'km') AS ok;
SELECT units.main.parse_quantity('5 km') AS q;
SELECT unit, base_unit
FROM units.main.supported_units()
WHERE dimension = 'length'
ORDER BY unit
LIMIT 5;
unit_catalog
Authoritative, versioned unit definitions (factor and offset per exact unit string) behind the strict conversion functions.
Show the factor and offset that define each temperature unit.
SELECT unit, factor, "offset"
FROM units.main.unit_catalog
WHERE dimension = 'temperature'
ORDER BY unit;
Report the worker and contract versions the definitions belong to.
SELECT DISTINCT implementation_version, contract_version
FROM units.main.unit_catalog
ORDER BY ALL;
Audit strict temperature conversions: convert 100 of each unit with convert_strict and recompute the same result from the factor and offset published in unit_catalog ((value * f.factor + f.offset - t.offset) / t.factor).
SELECT f.unit AS from_unit, t.unit AS to_unit,
round(units.main.convert_strict(100, f.unit, t.unit), 6) AS converted,
round((100 * f.factor + f."offset" - t."offset") / t.factor, 6) AS recomputed
FROM units.main.unit_catalog AS f
JOIN units.main.unit_catalog AS t ON t.dimension = f.dimension AND t.unit <> f.unit
WHERE f.unit IN ('°C', '°F', 'K') AND t.unit IN ('°C', '°F', 'K')
ORDER BY from_unit, to_unit;
2 more examples
SELECT unit, factor, "offset"
FROM units.main.unit_catalog()
WHERE dimension = 'temperature'
ORDER BY unit;
SELECT DISTINCT implementation_version, contract_version
FROM units.main.unit_catalog();
compatible (unit_a VARCHAR, unit_b VARCHAR)
Whether two units share a dimension (i.e. can be converted between). Unknown units are never compatible
Check whether two units can be converted between (true).
SELECT units.main.compatible('mi', 'km') AS ok;
Guard a conversion: convert each row to kilograms only when its unit is compatible with kg, so the length row ('m') yields NULL instead of an incompatible-dimension error.
SELECT id, qty, unit,
CASE WHEN units.main.compatible(unit, 'kg') THEN units.main.convert(qty, unit, 'kg') END AS kg
FROM (VALUES (1, 150.0, 'lb'), (2, 2.5, 'kg'), (3, 3.0, 'm'), (4, 16.0, 'oz')) AS t(id, qty, unit)
ORDER BY id;
convert (value ANY, from_unit VARCHAR, to_unit VARCHAR)
Convert a value between two units of the same dimension (NULL if a unit is unknown; ERROR if the dimensions are incompatible)
Convert a marathon distance from miles to kilometres.
SELECT units.main.convert(26.2, 'mi', 'km') AS km;
Convert a body temperature from Celsius to Fahrenheit (affine, offset-aware).
SELECT units.main.convert(37, '°C', '°F') AS fahrenheit;
convert_difference_strict (value DOUBLE, from_unit VARCHAR, to_unit VARCHAR)
Convert a finite quantity difference using scale factors without offsets; reject invalid units, nonfinite values and overflow; preserve valid NULL values
Convert a 10 degree Celsius temperature rise into Fahrenheit degrees.
SELECT units.main.convert_difference_strict(10, '°C', '°F') AS delta_f;
Convert a 5 km difference in distance into miles.
SELECT units.main.convert_difference_strict(5, 'km', 'mi') AS delta_mi;
Report each reactor's final temperature in °F with convert_strict and its rise in °F with convert_difference_strict: the 15 °C rise of reactor_a is 27 °F, not the 59 °F an absolute conversion would give.
SELECT sensor,
round(units.main.convert_strict(end_c, '°C', '°F'), 2) AS end_f,
round(units.main.convert_difference_strict(end_c - start_c, '°C', '°F'), 2) AS rise_f
FROM (VALUES ('reactor_a', 20.0, 35.0), ('reactor_b', 18.5, 21.0)) AS t(sensor, start_c, end_c)
ORDER BY sensor;
convert_strict (value DOUBLE, from_unit VARCHAR, to_unit VARCHAR)
Convert a finite absolute quantity using scale factors and offsets; reject invalid units, nonfinite values and overflow; preserve valid NULL values
Strictly convert a marathon distance from miles to kilometres.
SELECT units.main.convert_strict(26.2, 'mi', 'km') AS km;
Strictly convert the freezing point of water from Celsius to Fahrenheit (offset-aware).
SELECT units.main.convert_strict(0, '°C', '°F') AS fahrenheit;
dimension (unit VARCHAR)
Return the physical dimension of a unit ('length'|'mass'|'time'|…), or NULL if the unit is unknown
Identify the physical dimension of a unit (energy).
SELECT units.main.dimension('kWh') AS dim;
Group a column of unit strings by the dimension they measure.
SELECT units.main.dimension(u) AS dim, count(*) AS n
FROM (VALUES ('mi'), ('km'), ('kg'), ('lb')) AS t(u)
GROUP BY dim
ORDER BY dim;
parse_quantity (text VARCHAR)
Parse quantity text such as the string 5 km into a STRUCT(value DOUBLE, unit VARCHAR); NULL if unparseable or the unit is unknown
Parse a quantity string into a (value, unit) struct.
SELECT units.main.parse_quantity('5 km') AS q;
Parse a free-text quantity and convert it to another unit in one query.
WITH q AS (SELECT units.main.parse_quantity('26.2 mi') AS p) SELECT units.main.convert((p).value, (p).unit, 'km') AS km
FROM q;
Parse free-text readings, group them by physical dimension, and total each group in its SI base unit; '7 furlongs' is not a recognized unit, so it parses to NULL and is skipped.
WITH r AS (SELECT units.main.parse_quantity(txt) AS q FROM (VALUES ('5 km'), ('3 mi'), ('800 m'), ('2 kg'), ('12 lb'), ('7 furlongs')) AS t(txt)) SELECT units.main.dimension((q).unit) AS dim, count(*) AS readings, round(sum(units.main.to_base((q).value, (q).unit)), 4) AS total_si
FROM r
WHERE q IS NOT NULL
GROUP BY dim
ORDER BY dim;
to_base (value ANY, unit VARCHAR)
Express a value in the SI base unit of its dimension (NULL if the unit is unknown)
Express 100 centimetres in the SI base unit (metres).
SELECT units.main.to_base(100, 'cm') AS metres;
Reduce 1 GiB to bytes so mixed data sizes can be summed on a common base.
SELECT units.main.to_base(1, 'GiB') AS bytes;
Normalize mixed free-text readings to SI and label each with its base unit by joining the parsed unit to supported_units (e.g. '98.6 °F' becomes 310.15 K).
WITH r AS (SELECT txt, units.main.parse_quantity(txt) AS q FROM (VALUES ('5 km'), ('2 GiB'), ('1 kWh'), ('98.6 °F')) AS t(txt)) SELECT r.txt, units.main.to_base((r.q).value, (r.q).unit) AS base_value, s.base_unit
FROM r
JOIN units.main.supported_units AS s ON s.unit = (r.q).unit
ORDER BY r.txt;
| txt | base_value | base_unit |
|---|---|---|
| 1 kWh | 3,600,000 | J |
| 2 GiB | 2,147,483,648 | byte |
| 5 km | 5000 | m |
| 98.6 °F | 310.15 | K |
Try these queries
Convert a marathon distance from miles to kilometres.
SELECT units.main.convert(26.2, 'mi', 'km') AS km
Uses convert
Reduce 1 GiB to bytes via the SI base unit.
SELECT units.main.to_base(1, 'GiB') AS bytes
Uses to_base
Check whether two units can be converted between.
SELECT units.main.compatible('mi', 'km') AS ok
Uses compatible
Parse a free-text quantity string into a (value, unit) struct.
SELECT units.main.parse_quantity('5 km') AS q
Uses parse_quantity
List the recognized units in the length dimension.
SELECT unit, base_unit
FROM units.main.supported_units
WHERE dimension = 'length'
ORDER BY unit
Uses supported_units
19 more examples in the Catalog, each listed under the table or function it uses.
Units is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.
Related workers
Calendar
Dates, units & validation
Public holidays and business days for hundreds of countries, plus Easter, ISO weeks, and RRULE recurrences
Color
Dates, units & validation
Convert colors between hex, RGB, HSL and CIELAB, measure CIEDE2000 difference, and check WCAG contrast for accessibility
Conform
Dates, units & validation
Check and standardize phone numbers, emails, IBANs, EU VAT numbers, card numbers, URLs and postal codes offline, with no external service