Skip to content

MySQL engine doesn't support: CREATE TRIGGER, CREATE FUNCTION, CREATE PROCEDURE #1403

Closed

Description

@dansimau

Version

1.11.0

What happened?

$ sqlc compile
# package db
migrations/20210121143728_timestamps.up.sql:11:15: syntax error near "TRIGGER `update_timestamp_collections` BEFORE UPDATE ON `collections`"
migrations/20210421162816_uuidv4.up.sql:1:15: syntax error near "FUNCTION uuidv4()"
migrations/20220117154531_migrate_collections_to_user_collections_rel.up.sql:4:17: syntax error near "PROCEDURE _migrate_collection_sort_orders()"

Looks like these are not supported by the parser: pingcap/parser#988

Playground URL

https://play.sqlc.dev/p/8cb9a845afd03c6741aef0a13b221045c620690b6b6c5d9738eaeeaab4a7ab8e

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

Activity

  1. added
    bugSomething isn't working
    triageNew issues that hasn't been reviewed
    on Jan 30, 2022
  2. dansimau commented on Jan 30, 2022

    @dansimau
    ContributorAuthor

    It looks like pingcap/parser is missing quite a lot.

    I just had a look at what it would take to write a PR for the parser. In my case I have a stored procedure that uses a BEGIN/END, CURSOR, LOOP... this would be non-trivial to implement in pingcap/parser. And it's not at all relevant to sqlc I think.

    As a workaround, I now preprocess my migration files and use a script to filter out the problematic statements. I then feed the processed .sql migration files to sqlc.

    E.g. here is my Makefile:

    .PHONY: sqlc
    sqlc: gen-sqlc
    	sqlc compile
    
    .PHONY: gen-sqlc
    gen-sqlc: $(addprefix migrations/gen-sqlc/,$(shell cd migrations && find . -name '*.sql' -maxdepth 1))
    
    migrations/gen-sqlc/%.sql: migrations/%.sql
    	mkdir -p migrations/gen-sqlc
    	cat $< | \
    		python3 scripts/re-filter.py "BEGIN.*?END(?=\s*;)" | \
    		python3 scripts/re-filter.py "(CREATE|DROP) (TRIGGER|FUNCTION|PROCEDURE).*?;" \
    			> $@
    

    And source for re-filter.py: https://gist.github.com/dansimau/e8a88415cde5b22248399401bdc1b17c

    YMMV.

  3. added
    upstreamIssue is caused by a dependency
    and removed
    triageNew issues that hasn't been reviewed
    on Jan 31, 2022
  4. changed the title [-]mysql engine doesn't support: CREATE TRIGGER, CREATE FUNCTION, CREATE PROCEDURE[/-] [+]MySQL engine doesn't support: CREATE TRIGGER, CREATE FUNCTION, CREATE PROCEDURE[/+] on Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions