package pg_query

  1. Overview
  2. Docs

A thin wrapper around libpg_query.

type parse_error = {
  1. message : string;
    (*

    The error message

    *)
  2. funcname : string;
    (*

    The name of the parsing function where the error occurred

    *)
  3. filename : string;
    (*

    The filename of the parsing code where the error occurred

    *)
  4. lineno : int;
    (*

    The line number of filename where the error occurred

    *)
  5. cursorpos : int;
    (*

    The position in the query where the error occurred

    *)
  6. context : string option;
    (*

    Optional additional context

    *)
}

Represents a syntax error in parsing some SQL.

message and cursorpos are probably the most useful fields. Note that filename, funcname and lineno refer to the location in the parsing code that the error occured, not to the input SQL.

type parse_result = {
  1. parse_tree : string;
    (*

    The parse tree of the query, as JSON

    *)
  2. stderr_buffer : string option;
    (*

    A field of unknown purpose

    *)
  3. error : parse_error option;
    (*

    Some parse_error for queries where parsing failed and None for successful ones

    *)
}

Represents the overall result of a parse

val raw_parse : string -> parse_result

Parses a string containing SQL and return a parse_result corresponding to the libpg_query struct

val parse : string -> (string, string) Stdlib.result

Parses a string containing SQL and returns either Ok parse_tree or Error error_message

val show_parse_error : parse_error -> string

Derived function to display a parse error

val show_parse_result : parse_result -> string

Derived function to display a parse_result