For data teams

Review every schema, grant, model and query change.

For the platform engineers, analytics engineers and DBAs who own the warehouse and ship its SQL. Lexega reads each pull request and reports what it does to your tables, your numbers and your access controls.

curl -sSL https://lexega.com/install.sh | sh

Free to run. No key, no account, no email. macOS and Linux; Windows download. Start a 30-day trial

What changes for your team

See what a change does

Not which lines moved. A pull request that says it speeds up a model and quietly drops rows gets called out in the review.

Catch the changes that hurt

A delete that lost its filter. A masking policy removed. A grant to everyone. Retention set to zero on a schema.

One policy for every repository

Decide what blocks and what only warns. Every exception is reviewed and recorded.

The review lands where the change is discussed

Lexega compares the pull request with its base and posts what it found as a comment, on GitHub, GitLab, Azure DevOps or Bitbucket. Later pushes update the same comment, except on Bitbucket, where each run adds a new one.

dbt models are rendered as they will run, without dbt or Python on the runner. Packages are read from the project's dbt_packages/ folder, so run dbt deps first or commit that folder.

Rendering dbt needs no key. Comparing each change with its base, and following a column from model to model, need a trial or Team key. See one review with and without a key

Pull request · the top finding Lexega reported in each file

Speed up the revenue model

  1. governance/customers.sql · Critical · no key neededAvoid granting privileges to PUBLIC. Every user receives what PUBLIC is granted, which may expose data unintentionally.
  2. migrations/purge_staging.sql · Critical · needs a keyWrite to staging.events became unbounded after WHERE clause was removed. May affect entire table.
  3. models/active_revenue.sql · High · needs a keyOuter join's nullable side filtered in WHERE clause or by a later join. The unmatched rows the outer join keeps are dropped, likely a bug.
5 findings, 4 critical. A block-on-critical policy fails the check.All 5 findings
Every finding in this review, with rule IDs
Pull request: Speed up the revenue model3 files · 5 findings · 4 critical

governance/customers.sql

-ALTER TABLE crm.customers MODIFY COLUMN email SET MASKING POLICY pii.mask_email;
-GRANT SELECT ON TABLE crm.customers TO ROLE analyst;
+ALTER TABLE crm.customers MODIFY COLUMN email UNSET MASKING POLICY;
+GRANT SELECT ON TABLE crm.customers TO ROLE PUBLIC;
  • CriticalGRT-TO-PUBLICfree

    Avoid granting privileges to PUBLIC. Every user receives what PUBLIC is granted, which may expose data unintentionally.

  • CriticalTBL-MASK-RMVfree

    Masking or Projection Policy removed from column. This exposes PII or sensitive data.

migrations/purge_staging.sql

-DELETE FROM staging.events
-WHERE loaded_at < DATEADD(day, -30, CURRENT_DATE());
+DELETE FROM staging.events;
  • CriticalDIFF-WRITE-WHERE-RMVchangekey

    Write to staging.events became unbounded after WHERE clause was removed. May affect entire table.

  • CriticalDML-WRITE-UNBOUNDEDfree

    Unbounded write operation detected - the statement has no WHERE clause or its WHERE clause matches every row. This affects ALL rows in the target table(s).

models/active_revenue.sql

SELECT a.account_id, a.region, SUM(i.amount) AS revenue
FROM accounts a
LEFT JOIN invoices i
ON i.account_id = a.account_id
- AND i.status = 'posted'
WHERE a.status = 'active'
+ AND i.status = 'posted'
GROUP BY a.account_id, a.region;
  • HighQ-JOIN-LEFT-FILTkey

    Outer join's nullable side filtered in WHERE clause or by a later join. The unmatched rows the outer join keeps are dropped, likely a bug.

Recorded from lexega-sql review base..HEAD, version 3.0.0. Findings marked free appear without a license key. Findings marked key, including every change finding, need a trial or Team key.

Runs without error, does the wrong thing

Each example is real SQL with Lexega's verdict. Open one for the full statement, what the engine reported and a near-identical safe version that comes back allowed.

Recorded from lexega-sql 3.0.0 with a trial or Team key, under a policy that blocks critical findings and warns on high ones. Enforcing a policy needs no key; each example says what a run without one reports. To check one, install Lexega and run lexega-sql analyze on the example's SQL.

A revenue rollup that returns the wrong number

LEFT JOIN invoices i ON i.account_id = a.account_id
WHERE i.status = 'posted'
...
WHERE account_id NOT IN (SELECT account_id FROM suspended_accounts)

Warned. Its findings are high, which the demo policy warns on and does not block. Filters in the ON clause and NOT EXISTS are allowed with no finding.

Without a key: Q-NULL-NOTIN at high. The collapsed LEFT join, Q-JOIN-LEFT-FILT at high, needs a trial or Team key.

Full SQL, engine output and its safe twin

Misstatement: a revenue rollup that runs without error and returns the wrong number — three different ways, including a billable-only filter that is provably always true

-- A revenue rollup that runs without error and returns the wrong number.
WITH active AS (
  SELECT account_id, region FROM accounts WHERE status = 'active'
),
billable AS (
  SELECT a.account_id, SUM(i.amount) AS revenue
  FROM active a
  LEFT JOIN invoices i ON i.account_id = a.account_id
  WHERE i.status = 'posted'
    AND (i.is_billable = TRUE OR i.is_billable = FALSE OR i.is_billable IS NULL)
  GROUP BY a.account_id
)
SELECT * FROM billable
WHERE account_id NOT IN (SELECT account_id FROM suspended_accounts);
WARNEDfallback: severity_actions.high = warn
HIGHQ-JOIN-LEFT-FILT

Outer join's nullable side filtered in WHERE clause or by a later join. The unmatched rows the outer join keeps are dropped, likely a bug.

HIGHQ-NULL-NOTIN

NULL-logic hazard: NOT IN with a subquery that may return NULL. If the subquery returns any NULL, the NOT IN evaluates to UNKNOWN and filters all rows. Use NOT EXISTS or ensure the subquery has WHERE ... IS NOT NULL.

MEDIUMQ-PRED-TAUTOLOGY

Tautological predicate: condition is always true for non-NULL values (e.g., WHERE x=1 OR x<>1). The WHERE clause filters at most NULL rows.

lexega-sql 3.0.0 · snowflake · with a key

Same rollup, null-safe, really filtered. The join filters move into the ON clause so unmatched accounts survive, the billable filter actually filters, and NOT EXISTS is immune to a NULL in suspended_accounts.

-- The join filters live in the ON clause, so unmatched accounts survive;
-- NOT EXISTS is immune to a NULL in suspended_accounts.
WITH active AS (
  SELECT account_id, region FROM accounts WHERE status = 'active'
),
billable AS (
  SELECT a.account_id, SUM(i.amount) AS revenue
  FROM active a
  LEFT JOIN invoices i
    ON i.account_id = a.account_id
    AND i.status = 'posted'
    AND i.is_billable = TRUE
  GROUP BY a.account_id
)
SELECT * FROM billable b
WHERE NOT EXISTS (
  SELECT 1 FROM suspended_accounts s WHERE s.account_id = b.account_id
);
ALLOWEDAllowed — no critical or high findings

lexega-sql 3.0.0 · snowflake · with a key

A delete inside a string whose filter is always true

EXEC sp_executesql N'DELETE FROM dbo.audit_log
  WHERE batch_id = 42 OR retained = 0 OR batch_id <> 42 OR batch_id IS NULL';

Blocked. A delete with a real filter and a bound parameter is allowed.

Without a key: no finding. Reading the delete inside the string, DML-WRITE-UNBOUNDED at critical, needs a trial or Team key.

Full SQL, engine output and its safe twin

The dangerous statement is inside the string literal — and its WHERE clause is a lie. Lexega parses the embedded SQL and proves the filter is always true

-- The DELETE inside the literal has a WHERE clause — one that is
-- provably always true. The engine parses the embedded SQL and proves it.
CREATE PROCEDURE dbo.archive_stale
AS
BEGIN
  EXEC sp_executesql N'DELETE FROM dbo.audit_log
    WHERE batch_id = 42 OR retained = 0 OR batch_id <> 42 OR batch_id IS NULL';
END;
BLOCKEDBlocked by severity_actions.critical (finding severity = critical)
CRITICALDML-WRITE-UNBOUNDEDfound in dynamic SQL body

Unbounded write operation detected - the statement has no WHERE clause or its WHERE clause matches every row. This affects ALL rows in the target table(s).

MEDIUMQ-PRED-TAUTOLOGYfound in dynamic SQL body

Tautological predicate: condition is always true for non-NULL values (e.g., WHERE x=1 OR x<>1). The WHERE clause filters at most NULL rows.

lexega-sql 3.0.0 · mssql · with a key

Same shape, really bounded. The DELETE inside the literal has a WHERE clause that actually filters, with the cutoff bound as a parameter — the engine reads through the string either way and can tell a real bound from a fake one.

-- Same shape. The DELETE inside the literal is bounded for real, and
-- the cutoff arrives as a bound parameter.
CREATE PROCEDURE dbo.archive_stale @cutoff DATETIME2
AS
BEGIN
  EXEC sp_executesql
    N'DELETE FROM dbo.audit_log WHERE logged_at < @c',
    N'@c DATETIME2', @c = @cutoff;
END;
ALLOWEDAllowed — no critical or high findings

lexega-sql 3.0.0 · mssql · with a key

A grant to everyone

GRANT ALL PRIVILEGES ON DATABASE finance TO ROLE reporting;
GRANT SELECT ON ALL TABLES IN SCHEMA finance.ledger TO ROLE PUBLIC;

Blocked. Usage and one table, granted to the role that reads it, is allowed.

Without a key: the same findings, GRT-TO-PUBLIC at critical and GRT-ALL-PRIV at high.

Full SQL, engine output and its safe twin

Privilege: a grant that hands the ledger to every user in the account, next to one that grants everything

-- A reporting role gets everything on the finance database,
-- and every user in the account can read the ledger.
GRANT ALL PRIVILEGES ON DATABASE finance TO ROLE reporting;
GRANT SELECT ON ALL TABLES IN SCHEMA finance.ledger TO ROLE PUBLIC;
BLOCKEDBlocked by severity_actions.critical (finding severity = critical)
CRITICALGRT-TO-PUBLIC

Avoid granting privileges to PUBLIC. Every user receives what PUBLIC is granted, which may expose data unintentionally.

HIGHGRT-ALL-PRIV

Avoid GRANT ALL PRIVILEGES. Use specific privilege grants to follow the principle of least privilege.

lexega-sql 3.0.0 · snowflake · with a key

Same role, least privilege. The reporting role gets usage and one table, granted to the role that reads it, so the same change is allowed.

-- The reporting role gets what the dashboard reads, and nothing else.
GRANT USAGE ON DATABASE finance TO ROLE reporting;
GRANT USAGE ON SCHEMA finance.ledger TO ROLE reporting;
GRANT SELECT ON TABLE finance.ledger.gl_summary TO ROLE reporting;
ALLOWEDAllowed — no critical or high findings

lexega-sql 3.0.0 · snowflake · with a key

Your access model, as a rule

The built-in rules catch what is risky anywhere. Your own rules catch what breaks your conventions: here, a grant on any production object to a role outside the access model.

Pass the file with --custom-rules. A grant on PROD.SALES.ORDERS to INTERN is reported as critical; the same grant to ANALYST_RO, or on a DEV table, is not.

Custom rules are free. They run on the same engine and see the same facts as the built-in rules. Write your own

data-team-rules.yaml
rules:
  - id: ACME-PROD-GRANTS
    risk_level: critical
    message: "Grants on PROD go only to the roles in our access model."
    triggers:
      all_of:
        - kind: grant
        - privilege.target.name.canonical: { matches: "PROD.*" }
        - privilege.grantees:
            exists:
              name.normalized: { not_in: [ANALYST_RO, BI_READER] }

Works with what you run

Warehouses and databases

Snowflake, Databricks, SQL Server, PostgreSQL, BigQuery, MySQL, Redshift

Code

Migrations, dbt models, stored procedures, SQL in Python and notebooks

Pipelines

GitHub, GitLab, Azure DevOps, Bitbucket

Questions data teams ask

We already have dbt tests and catalog permissions.
Those check data and access once things run. Lexega checks the change while it is still a pull request. They work together.
Is this a style linter?
No. Its findings are about what the SQL does: the rows a write touches, the rows a join drops, the grants and policies a change alters. It runs alongside whatever formatter or style linter you use.
Will it be noisy?
By default only high and critical findings are shown, and nothing blocks until your policy says so. Start in report-only mode, and lower or switch off any built-in rule that does not fit your conventions by its ID:
rules:
  - id: SCHEMA-DROP
    risk_level: low
Does it need access to our warehouse?
No. It reads SQL files. Pulling the catalog for richer findings is optional.
What does it cost?
It is free to run without a key. A Team license covers up to 25 people who commit SQL. See pricing

Run it on your repository today

Install free and analyze plain SQL in a minute. dbt rendering and policy enforcement need no key. A 30-day trial key adds the comparison of each change with its base and analysis across statements.