Skip to content

Add .parse_plpgsql method to parse PL/pgSQL function definitions - #316

Open
lfittl wants to merge 1 commit into
mainfrom
add-parse-plpgsql
Open

Add .parse_plpgsql method to parse PL/pgSQL function definitions#316
lfittl wants to merge 1 commit into
mainfrom
add-parse-plpgsql

Conversation

@lfittl

@lfittl lfittl commented May 17, 2024

Copy link
Copy Markdown
Member

This uses Postgres' PL/pgSQL parser (as extracted in libpg_query) to parse a PL/pgSQL CREATE FUNCTION statement into the AST.

TODO

  • Add a test showing an example

This uses Postgres' PL/pgSQL parser (as extracted in libpg_query)
to parse a PL/pgSQL CREATE FUNCTION statement into the AST.
@@ -0,0 +1,43 @@
require 'json'
module PgQuery

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
module PgQuery
module PgQuery

module PgQuery
class PlpgsqlParseError < ArgumentError
attr_reader :location
def initialize(message, source_file, source_line, location)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def initialize(message, source_file, source_line, location)
def initialize(message, source_file, source_line, location)

@spacebat

Copy link
Copy Markdown

Hi, I have some interest in this functionality and am using a fork. Is this PR likely to be merged more-or-less in its current form?

BTW thanks @lfittl and @olleolleolle for all your efforts with this library!

@lfittl

lfittl commented Aug 30, 2025

Copy link
Copy Markdown
Member Author

Hi, I have some interest in this functionality and am using a fork. Is this PR likely to be merged more-or-less in its current form?

Good question!

I've been meaning to merge this in, but haven't yet. One of the key reasons why is that I'm not sure whether we shouldn't also be using a Protobuf-based struct for the PL/PgSQL parsing, instead of JSON. That'd require changing this on the libpg_query side. I may try to do that once we rebase libpg_query for Postgres 18 (end of September timeframe), and I'd rework this PR on that version then.

Out of curiosity, what's your use case for function definition parsing?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants