Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SQL Functions #492

Closed
timvandam opened this issue Feb 12, 2023 · 1 comment · Fixed by #493
Closed

Support SQL Functions #492

timvandam opened this issue Feb 12, 2023 · 1 comment · Fixed by #493

Comments

@timvandam
Copy link

Is your feature request related to a problem? Please describe.
I want to use a trigger to manage my "UpdatedAt" columns. This trigger calls a SQL Function that updates this column to the current timestamp. Currently, pgtyped is unable to parse functions.

E.g.:

/* @name CreateUpdatedAtFunction */
CREATE FUNCTION UpdatedAt()
RETURNS TRIGGER AS $$
    BEGIN
        NEW.updatedAt = NOW();
        RETURN NEW;
    END;
$$ LANGUAGE plpgsql;

Yields

17 | /* @name CreateUpdatedAtFunction */
18 | CREATE FUNCTION UpdatedAt()
19 | RETURNS TRIGGER AS $$
20 |     BEGIN
21 |         NEW.updatedAt = NOW();
22 >         RETURN NEW;
23 |     END;
24 | $$ LANGUAGE plpgsql;
25 | 
26 | 
Errors:
- (22:8) Parse error: extraneous input 'RETURN' expecting {<EOF>, '/*'}

Describe the solution you'd like
Support for this. I think that in principle all this requires is skipping the code block (i.e. the part delimited by $$.

@timvandam
Copy link
Author

timvandam commented Feb 12, 2023

Note that the $$ delimiters can also contain text. Any delimiter starting and ending with $ will do. E.g. $updated_at_trigger_fn$ <code here> $updated_at_trigger_fn$ works too

https://www.postgresqltutorial.com/postgresql-plpgsql/dollar-quoted-string-constants/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant