---
name: "pgFormatter::CGI"
section: "3pm"
platform: "linux"
package: "pgformatter"
version: "5.11-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/pgFormatter::CGI"
---

# pgFormatter::CGI(3pm)

Implementation of CGI-BIN script to format SQL queries.

## NAME

pgFormatter::CGI - Implementation of CGI-BIN script to format SQL queries.

## VERSION

Version 5.11

## SYNOPSIS

This module is called by pg\_format program, when it detects it is run in CGI environment. In such case all control over flow is passed to this module by calling:

```
    my $program = pgFormatter::CGI->new();
    $program->run()
```

## FUNCTIONS

### new

Object constructor, calls set\_config method to set default values for various parameters.

### run

Route to the right handler based on what sort of data we receive

### run\_webpage

Wraps all work related to generating html page.

It calls set of functions to get CGI object, receive parameters from request, sanitize them, beautify query (if provided) and print ghtml.

### run\_api

Wraps all work related to generating JSON response when used as API.

### get\_cgi

Creates CGI object, and sets POST size limit

###

Sets config for the page and beautifier. URLs, names of auxiliary files, configuration for pgFormatter::Beautify module.

###

Loads, and returns, default CSS from \_\_DATA\_\_.

###

Gets values of parameters, and possibly uploaded file from CGI object to structures in `$self`.

###

Get params for the API version of this service

### sanitize\_params

Overrides parameter values if given values were not within acceptable ranges.

### beautify\_query

Runs beautification on provided query, and stores new version in `$self`-\>{'content'}

### print\_json

Outputs beautified SQL as JSON

###

Outputs body of the page.

### print\_footer

Outputs footer of the page

### \_load\_optional\_file

Helper function to try to load file. If it succeeds, it returns file content, it not, it returns empty string (instead of dying).

### print\_error

Outputs an error message when no acceptable response is found.

### print\_headers

Outputs page headers - both HTTP level headers, and HTML.

## DATA

\_\_DATA\_\_ section (at the end of this file) is used to store default CSS Style, so that it will not "pollute" Perl code, and will not need to be indented.

## AUTHOR

pgFormatter is an original work from Gilles Darold

## BUGS

Please report any bugs or feature requests to: https://github.com/darold/pgFormatter/issues

## COPYRIGHT

Copyright 2012-2026 Gilles Darold. All rights reserved.

## LICENSE

pgFormatter is free software distributed under the PostgreSQL Licence.

A modified version of the SQL::Beautify Perl Module is embedded in pgFormatter with copyright (C) 2009 by Jonas Kramer and is published under the terms of the Artistic License 2.0.
