All Projects → auxten → postgresql-parser

auxten / postgresql-parser

Licence: other
Pure Golang PostgreSQL (SQL:2011, SQL:2008, SQL:2003, SQL:1999, and SQL-92 Standard) Parser

Programming Languages

go
31211 projects - #10 most used programming language
Yacc
648 projects

Projects that are alternatives of or similar to postgresql-parser

perseus
Perseus is a set of scripts (docker+javascript) to investigate a distributed database's responsiveness when one of its three nodes is isolated from the peers
Stars: ✭ 49 (-70.3%)
Mutual labels:  cockroachdb
sql-parser
解析 mysql create table 语句,用于通过建表语句生成 model 代码文件。
Stars: ✭ 17 (-89.7%)
Mutual labels:  sql-parser
PHP-Light-SQL-Parser
This class can parse SQL to get query type, tables, field values, etc.. It takes an string with a SQL statements and parses it to extract its different components. Currently the class can extract the SQL query method, the names of the tables involved in the query and the field values that are passed as parameters. This parser is pretty light re…
Stars: ✭ 23 (-86.06%)
Mutual labels:  sql-parser
sql-ddl-to-json-schema
SQL DDL to JSON Schema Converter
Stars: ✭ 138 (-16.36%)
Mutual labels:  sql-parser
sqlfun
Modern SQL parser using Bison (Yacc) and Flex
Stars: ✭ 63 (-61.82%)
Mutual labels:  sql-parser
lacquer
SQL Parser derived from Presto, written in Python with the PLY framework
Stars: ✭ 29 (-82.42%)
Mutual labels:  sql-parser
simple-ddl-parser
Simple DDL Parser to parse SQL (HQL, TSQL, AWS Redshift, BigQuery, Snowflake and other dialects) ddl files to json/python dict with full information about columns: types, defaults, primary keys, etc. & table properties, types, domains, etc.
Stars: ✭ 76 (-53.94%)
Mutual labels:  sql-parser
SQLParser
SQL-Parser
Stars: ✭ 13 (-92.12%)
Mutual labels:  sql-parser
Pony
Pony Object Relational Mapper
Stars: ✭ 2,762 (+1573.94%)
Mutual labels:  cockroachdb
Db
Data access layer for PostgreSQL, CockroachDB, MySQL, SQLite and MongoDB with ORM-like features.
Stars: ✭ 2,832 (+1616.36%)
Mutual labels:  cockroachdb
Typeorm
ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
Stars: ✭ 26,559 (+15996.36%)
Mutual labels:  cockroachdb
Cockroach
CockroachDB - the open source, cloud-native distributed SQL database.
Stars: ✭ 22,700 (+13657.58%)
Mutual labels:  cockroachdb
activerecord-cockroachdb-adapter
CockroachDB adapter for ActiveRecord.
Stars: ✭ 90 (-45.45%)
Mutual labels:  cockroachdb
datastation
App to easily query, script, and visualize data from every database, file, and API.
Stars: ✭ 2,519 (+1426.67%)
Mutual labels:  cockroachdb
go-distsys
Distributed Systems programming examples in the Go programming language.
Stars: ✭ 101 (-38.79%)
Mutual labels:  cockroachdb

What's this

PostgreSQL style Parser splitted from CockroachDB

See: Complex SQL format example

I tried to import github.com/cockroachdb/cockroach/pkg/sql/parser, but the dependencies is too complex to make it work.

To make things easy, I did these things:

  1. Copy all the pkg/sql/parser, pkg/sql/lex and simplify the dependencies
  2. Simplify the Makefile to just generate the goyacc stuff
  3. Add the goyacc generated files in parser and lex to make go get work easily, see the .gitignore files
  4. Trim the etcd dependency, see the go.mod
  5. Rename all test file except some pkg/sql/parser tests
  6. Add all necessary imports to vendor
  7. Remove the panic of meeting unregistried functions, see the WrapFunction
  8. Other nasty things make the parser just work that I forgot :p

Who is using this

Features

  • Pure golang implementation
  • Almost full support of PostgreSQL (cockroachdb style PostgreSQL)
  • For SQL lineage analysis see go-sql-lineage

SQL Standard Compliance

The code is derived from CockroachDB v20.1.11 which supports most of the major features of SQL:2011. See:

How to use

package main

import (
	"log"
	
	"github.com/auxten/postgresql-parser/pkg/sql/parser"
	"github.com/auxten/postgresql-parser/pkg/walk"
)

func main() {
	sql := `select marr
			from (select marr_stat_cd AS marr, label AS l
				  from root_loan_mock_v4
				  order by root_loan_mock_v4.age desc, l desc
				  limit 5) as v4
			LIMIT 1;`
	w := &walk.AstWalker{
		Fn: func(ctx interface{}, node interface{}) (stop bool) {
			log.Printf("node type %T", node)
			return false
		},
	}
	
	stmts, err := parser.Parse(sql)
	if err != nil {
		return
	}
	
	_, _ = w.Walk(stmts, nil)
	return
}

SQL parser

This project contains code that is automatically generated using goyacc. goyacc reads the SQL expressions (sql.y) and generates a parser which could be used to tokenize a given input. You could update the generated code using the generate target inside the project's Makefile.

$ make generate

Progress

  • 2021-02-16 github.com/auxten/postgresql-parser/pkg/sql/parser Unit tests works now!
  • 2021-03-08 Add walker package.
  • 2022-08-03 Remove vendored dependencies by @mostafa in #19

Todo

  • Fix more unit tests
  • Make built-in function parsing work
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].