Skip to content

SQL parser fails to recognize WITH clause (Common Table Expressions) #1121

@andreameneghello

Description

@andreameneghello

The SQL parser doesn't recognize queries starting with WITH (CTEs). The sqlOperations map in v3/internal/sqlparse/sqlparse.go is missing an entry for "with", causing these queries to not be tracked in New Relic.

Steps to Reproduce

  1. Use nrpgx5.NewTracer() with the PostgreSQL driver
  2. Execute a CTE query:
WITH temp_results AS (
  SELECT id, name FROM users WHERE active = true
)
SELECT * FROM temp_results
  1. Query is not properly parsed/tracked

Expected Behavior

CTE queries should be recognized and tracked like other SQL operations.

Your Environment

  • Go Agent: v3 (latest)
  • Integration: nrpgx5
  • Database: PostgreSQL

Root Cause

The sqlOperations map in v3/internal/sqlparse/sqlparse.go is missing:

"with": nil,

Additional context

Proposed Fix:

Add "with": nil to the sqlOperations map, following the same pattern as "call", "create", "drop", etc.

CTEs are a standard SQL feature (SQL:1999) widely used in PostgreSQL. Users shouldn't need custom parsers for this common operation.

Current workaround: Custom parser function with "with" added to the map.


Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions