| 116 | } |
| 117 | |
| 118 | func TestCreateFunctionWithPgquery(t *testing.T) { |
| 119 | t.Setenv("PSQLDEF_PARSER", "pgquery") |
| 120 | postgresParser := NewParser() |
| 121 | |
| 122 | statements, err := postgresParser.Parse(` |
| 123 | CREATE FUNCTION increment(i integer) RETURNS integer |
| 124 | LANGUAGE plpgsql |
| 125 | AS $$ |
| 126 | BEGIN |
| 127 | RETURN i + 1; |
| 128 | END; |
| 129 | $$; |
| 130 | `) |
| 131 | |
| 132 | if err != nil { |
| 133 | t.Fatalf("failed to parse CREATE FUNCTION: %v", err) |
| 134 | } |
| 135 | |
| 136 | if len(statements) != 1 { |
| 137 | t.Fatalf("expected 1 statement, got %d", len(statements)) |
| 138 | } |
| 139 | |
| 140 | funcStmt := statements[0].Statement |
| 141 | _, ok := funcStmt.(*parser.Ignore) |
| 142 | if !ok { |
| 143 | t.Errorf("expected Ignore, got %T", funcStmt) |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | func TestCreateFunctionAutoModeFallbackRetry(t *testing.T) { |
| 148 | // Force Auto mode regardless of an ambient PSQLDEF_PARSER (the dev/CI default |