BEEM Functions

A reference of SQL functions you can call from your warehouse to enrich, transform, or validate data inline in any query.

BEEM provides a set of SQL functions you can call from your warehouse to enrich, transform, or validate data inline in any query. Just call them like any other SQL function.

All functions below are external functions — they run against BEEM-managed services, so no setup is required in your workspace.

🚧

Rate limits apply

Each function wraps an underlying API (Google, Genderize, Revenu Québec, Bedrock, BEEM internal APIs, etc.) with its own rate limits and quotas. Queries that call a function on many rows can exceed those limits quickly. If you're running a function over a large table, batch your work — e.g. WHERE id BETWEEN X AND Y — or schedule it incrementally rather than running it against the whole table at once.


AI

Apply AI to a row

SQLf_ai(effort, prompt, value)

Apply a natural-language prompt to any value in your query and get an AI-generated result back.

Parameters

NameTypeDescription
effortVARCHAR'low', 'med', or 'high' — higher effort is more capable but slower and more expensive.
promptVARCHARThe instruction to apply to each row (e.g. 'Summarize this review in 5 words').
valueVARCHARThe row value to run the prompt against.

Returns

TypeDescription
VARCHAR(MAX)The AI-generated text.

Example

WITH reviews AS (
  SELECT 1 AS review_id, 'Arrived on time and exactly as described, very happy.' AS review_text
  UNION ALL SELECT 2, 'Fabric feels cheap and the color is not what was shown online.'
  UNION ALL SELECT 3, 'Customer service was excellent, they resolved my issue in minutes.'
)
SELECT
  review_id,
  f_ai('low', 'Summarize this review in 5 words:', review_text) AS summary
FROM reviews;

Tips

  • Start with 'low' — it's fast and cheap, and works well for most classification, summarization, and extraction tasks.
  • Use 'high' only when you need the best possible reasoning (nuanced rewrites, multi-step logic).
  • Prompts are applied per row — if you have 10,000 rows, the function runs 10,000 times. Test on a small sample first (LIMIT 10) before running on a large table.

Address & Geocoding

Look up an address from a postal code

SQLf_google_addr_from_postal(postal_code, api_key)

Look up a full postal address from a postal or ZIP code using the Google Geocoding API.

Parameters

NameTypeDescription
postal_codeVARCHARThe postal or ZIP code to look up (e.g. 'K1A 0A6').
api_keyVARCHARYour Google Maps API key.

Returns

TypeDescription
VARCHARThe formatted address.

Example

SELECT f_google_addr_from_postal('K1A 0A6', 'YOUR_GOOGLE_API_KEY') AS address;

Distance between two addresses

SQLf_google_dist_between_addr(address_1, address_2, api_key)

Calculate the driving distance between two addresses using the Google Maps Distance Matrix API.

Parameters

NameTypeDescription
address_1VARCHARFirst address.
address_2VARCHARSecond address.
api_keyVARCHARYour Google Maps API key.

Returns

TypeDescription
FLOATDistance in meters.

Example

SELECT f_google_dist_between_addr(
  '123 Main St, Montreal, QC',
  '456 Oak Ave, Toronto, ON',
  'YOUR_GOOGLE_API_KEY'
) AS distance_m;

Names & Demographics

Predict gender from a first name

SQLf_assume_gender_from_firstname(first_name)

Predict the likely gender associated with a given first name, based on statistical data from the public Genderize.io API.

Parameters

NameTypeDescription
first_nameVARCHARThe first name to analyze.

Returns

TypeDescription
VARCHARA JSON-like string containing the prediction (gender, probability, count, timestamp).

Example

SELECT f_assume_gender_from_firstname('John') AS predicted_gender;

Validation

Validate a Quebec TVQ number

SQLf_revenuquebec_tvq_validate(tvq_number)

Validate a Quebec sales tax (TVQ) number against Revenu Québec's registry.

Parameters

NameTypeDescription
tvq_numberVARCHARThe TVQ number to validate (e.g. '1234567890TQ0001').

Returns

TypeDescription
VARCHAR(MAX)JSON with the validation result.

Example

SELECT f_revenuquebec_tvq_validate('1234567890TQ0001') AS tvq_validation;

Data Conversion

Convert Maestro XML to JSON

SQLf_maestro_xml_to_json(xml)

Convert a Maestro-formatted XML string into JSON. Useful for flattening XML payloads stored in a column.

Parameters

NameTypeDescription
xmlVARCHARThe XML string to convert.

Returns

TypeDescription
VARCHAR(MAX)The JSON representation.

Example

SELECT f_maestro_xml_to_json(xml_column) AS as_json
FROM source_table;

BEEM Platform Metadata

These functions return metadata about your BEEM workspace — useful for building dashboards and monitoring usage directly from SQL.

List datasets in a workspace

SQLf_list_datasets(workspace_id)

List all dataset IDs available in a given workspace.

Parameters

NameTypeDescription
workspace_idVARCHARThe workspace to list datasets from.

Returns

TypeDescription
VARCHAR(MAX)JSON array of dataset IDs.

Example

SELECT f_list_datasets('your-workspace-id') AS dataset_ids;

Get dataset metadata

SQLf_get_dataset_metadata(dataset_id)

Get metadata (name, owner, columns, etc.) for a single dataset.

Parameters

NameTypeDescription
dataset_idVARCHARThe UUID of the dataset to look up.

Returns

TypeDescription
VARCHAR(MAX)JSON object with the dataset's metadata.

Example

SELECT f_get_dataset_metadata('some-dataset-uuid') AS metadata;

Get my organization's consumption

SQLf_get_my_consumption(start_date)

Same as f_get_consumption, but pre-configured for your current organization — just pass a start date.

Parameters

NameTypeDescription
start_dateVARCHARISO date to start from (e.g. '2026-02-01').

Returns

TypeDescription
VARCHAR(MAX)JSON array of daily {date, dpu, storage} records.

Example

SELECT f_get_my_consumption('2026-02-01') AS consumption;

Need help?

If you'd like to request a new function or report an issue with an existing one, contact the BEEM team at [email protected].