
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
vertica-sqlglot-dialect
Advanced tools
A comprehensive Vertica dialect implementation for SQLGlot, a Python SQL parser and transpiler.
This Vertica dialect provides full-featured support for Vertica SQL syntax, including:
DATEADD(unit, interval, timestamp) - Add intervals to dates/timestampsDATEDIFF(unit, start_date, end_date) - Calculate date differencesDATE_TRUNC(unit, timestamp) - Truncate timestamps to specified unitTO_CHAR(timestamp, format) - Format timestamps as stringsTO_DATE(string, format) - Parse strings as datesTO_TIMESTAMP(string, format) - Parse strings as timestampsCURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, NOW()ILIKE / NOT ILIKE - Case-insensitive pattern matchingLIKE / NOT LIKE - Case-sensitive pattern matchingSUBSTRING(string, start, length) - Extract substringsTRIM() - Remove whitespaceLENGTH, UPPER, LOWER, etc.)RANDOM() - Generate random numbersABS, CEIL, FLOOR, ROUND, SQRT, POWER)MD5(string) - MD5 hashSHA1(string) - SHA1 hashARRAY[...] syntax for array literalsROW_NUMBER(), RANK(), LAG(), LEAD(), etc.OVER clauses with PARTITION BY and ORDER BYpip install vertica-sqlglot-dialect
For development:
pip install vertica-sqlglot-dialect[dev]
from sqlglot import transpile, parse_one
# Parse and generate Vertica SQL
sql = "SELECT DATEADD(DAY, 1, CURRENT_DATE)"
parsed = parse_one(sql, read="vertica")
generated = parsed.sql(dialect="vertica")
print(generated) # SELECT DATEADD(DAY, 1, CURRENT_DATE)
# Transpile from other dialects to Vertica
postgres_sql = "SELECT NOW()"
vertica_sql = transpile(postgres_sql, read='postgres', write='vertica')[0]
print(vertica_sql) # SELECT CURRENT_TIMESTAMP
# Complex query with CTEs and window functions
complex_query = """
WITH sales_data AS (
SELECT
region,
DATE_TRUNC(MONTH, sale_date) AS month,
SUM(amount) AS total_sales,
ROW_NUMBER() OVER (PARTITION BY region ORDER BY SUM(amount) DESC) AS rank
FROM sales
WHERE sale_date >= CURRENT_DATE - INTERVAL '1' YEAR
GROUP BY region, DATE_TRUNC(MONTH, sale_date)
)
SELECT
region,
month,
total_sales,
CASE
WHEN rank = 1 THEN 'Top Month'
ELSE 'Other'
END AS category
FROM sales_data
WHERE rank <= 5
ORDER BY region, total_sales DESC
"""
parsed = parse_one(complex_query, read="vertica")
print(parsed.sql("vertica", pretty=True))
# Date functions
sql = "SELECT DATEDIFF(DAY, '2023-01-01', '2023-12-31')"
result = parse_one(sql, read="vertica").sql("vertica")
# Array operations
sql = "SELECT ARRAY[1, 2, 3, 4, 5]"
result = parse_one(sql, read="vertica").sql("vertica")
# Case-insensitive matching
sql = "SELECT * FROM users WHERE name ILIKE '%john%'"
result = parse_one(sql, read="vertica").sql("vertica")
# Timestamp with timezone
sql = "CREATE TABLE events (id INTEGER, created_at TIMESTAMPTZ)"
result = parse_one(sql, read="vertica").sql("vertica")
git clone https://github.com/luisdelatorre/vertica-sqlglot-dialect.git
cd vertica-sqlglot-dialect
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -e .[dev]
# Run all tests
pytest
# Run with coverage
pytest --cov=vertica_sqlglot_dialect
# Run specific test file
pytest tests/test_vertica.py
# Run specific test method
pytest tests/test_vertica.py::TestVertica::test_vertica_date_functions
# Format code
black vertica_sqlglot_dialect tests
# Sort imports
isort vertica_sqlglot_dialect tests
# Type checking
mypy vertica_sqlglot_dialect
The dialect includes comprehensive tests covering:
The test suite follows the same patterns as other SQLGlot dialect tests, ensuring consistency and reliability.
Contributions are welcome! Please:
MIT License - see LICENSE file for details.
This package includes comprehensive examples demonstrating various use cases. See the examples/ directory for detailed demonstrations.
# Run basic usage examples
python examples/basic_usage.py
# Run advanced transformation examples
python examples/advanced_transformations.py
# Run data migration examples
python examples/data_migration.py
# Run performance analysis examples
python examples/performance_analysis.py
# Run comprehensive demonstration
python examples/run_all_examples.py
examples/basic_usage.py - Fundamental operations
examples/advanced_transformations.py - AST manipulation
examples/data_migration.py - Database migration
examples/performance_analysis.py - Query optimization
# Database Migration
from sqlglot import transpile
from sqlglot_vertica.vertica import Vertica
vertica_sql = "SELECT DATEDIFF('day', hire_date, CURRENT_DATE) FROM employees"
postgres_sql = transpile(vertica_sql, read=Vertica, write="postgres")[0]
# Query Analysis
from sqlglot import parse_one
ast = parse_one("SELECT MD5(email) FROM users WHERE active = true", read=Vertica)
tables = [table.name for table in ast.find_all(exp.Table)]
functions = [func.sql() for func in ast.find_all(exp.Func)]
# Error Handling
from sqlglot.errors import ParseError, UnsupportedError
try:
parse_one("SELECT $$invalid syntax$$", read=Vertica)
except ParseError as e:
print(f"Parse error: {e}")
FAQs
Vertica SQL dialect implementation for sqlglot
We found that vertica-sqlglot-dialect demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.