parsegres
Parsegres
Parsegres provides a Postgres-compatible SQL parser.
Installation
-
Add the dependency to your
shard.yml:dependencies: parsegres: github: jgaskins/parsegres -
Run
shards install
Usage
The main use case is to parse a SQL query using the Parsegres.parse method:
require "parsegres"
query = Parsegres.parse(<<-SQL)
SELECT *
FROM users
WHERE status = $1
AND group_id = $2
LIMIT 25
SQL
Supported statements
| Statement | Notes |
|---|---|
SELECT |
CTEs, set operations (UNION, et al), subqueries, JOINs, window functions |
INSERT |
VALUES, DEFAULT VALUES, INSERT … SELECT, RETURNING |
UPDATE |
FROM, RETURNING |
DELETE |
USING, RETURNING |
CREATE TABLE |
Column/table constraints, TEMP, IF NOT EXISTS, schema-qualified |
ALTER TABLE |
{ADD,DROP,ALTER,RENAME} COLUMN, ADD/DROP CONSTRAINT |
DROP TABLE |
IF EXISTS, CASCADE/RESTRICT, multiple tables |
CREATE INDEX |
UNIQUE, CONCURRENTLY, USING, partial indexes, IF NOT EXISTS |
DROP INDEX |
CONCURRENTLY, IF EXISTS, multiple indexes |
CREATE VIEW |
OR REPLACE, TEMP, IF NOT EXISTS, explicit column list |
DROP VIEW |
IF EXISTS, CASCADE/RESTRICT, multiple views |
TRUNCATE |
Multiple targets, ONLY, RESTART/CONTINUE IDENTITY, CASCADE/RESTRICT |
CREATE SEQUENCE |
All standard options (INCREMENT BY, MINVALUE/MAXVALUE, START, CACHE, CYCLE, OWNED BY) |
ALTER SEQUENCE |
Same options as CREATE SEQUENCE, plus RESTART |
DROP SEQUENCE |
IF EXISTS, CASCADE/RESTRICT, multiple sequences |
CREATE SCHEMA |
IF NOT EXISTS, AUTHORIZATION |
DROP SCHEMA |
IF EXISTS, CASCADE/RESTRICT, multiple schemas |
CREATE EXTENSION |
IF NOT EXISTS |
DROP EXTENSION |
IF EXISTS, CASCADE/RESTRICT, multiple extensions |
CREATE TYPE |
Range types (AS RANGE) |
CREATE RULE |
OR REPLACE, event routing, DO ALSO/DO INSTEAD |
DO |
Anonymous code blocks, optional LANGUAGE |
BEGIN |
Optional WORK/TRANSACTION |
COMMIT |
Optional WORK/TRANSACTION |
ROLLBACK |
Optional WORK/TRANSACTION |
Not yet implemented
The following statement types are not currently supported. PRs welcome!
CREATE TYPE— composite types, enums, domains (range types are supported)DROP TYPE— dropping typesGRANT/REVOKE— privilege managementCREATE FUNCTION/DROP FUNCTION— user-defined functionsCREATE TRIGGER/DROP TRIGGER— trigger managementCREATE MATERIALIZED VIEW/REFRESH MATERIALIZED VIEW/DROP MATERIALIZED VIEWALTER VIEW— modifying existing viewsALTER SEQUENCEadvanced options —OWNED BYreassignment,AS typeSAVEPOINT/RELEASE SAVEPOINT/ROLLBACK TO SAVEPOINTLOCK TABLEVACUUM/ANALYZECOPYEXPLAIN
Contributing
- Fork it (https://github.com/jgaskins/parsegres/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Jamie Gaskins - creator and maintainer
Repository
parsegres
Owner
Statistic
- 0
- 1
- 3
- 0
- 0
- 5 days ago
- February 23, 2026
License
MIT License
Links
Synced at
Thu, 05 Mar 2026 05:17:12 GMT
Languages