___         _      _
                 _ __  __ _/ __| __ _ _(_)_ __| |_
                | '_ \/ _` \__ \/ _| '_| | '_ \  _|
                | .__/\__, |___/\__|_| |_| .__/\__|
                |_|   |___/              |_|

Table of Contents

Overview / introduction
pgScript install
Requirements
Basic install
Usage
Synopsis
Options
Example
pgScript scripting language reference

Overview / introduction

pgScript enhances PostgreSQL SQL commands with these additional features:

For instance:

    SET @A = INTEGER(0, 10);           -- Random integer generator into @A
    IF (SELECT COUNT(*) FROM table)    -- Then table exists
    BEGIN
        SET @B = SELECT * FROM table;  -- Stores result of the query in @B
        INSERT INTO table VALUES (@A); -- Inserts a random integer
        PRINT @B;                      -- Prints result of the previous query
    END
    ELSE                               -- Else table does not exist
    BEGIN
        CREATE TABLE table ( ... );    -- Regular PostgreSQL command
    END

pgScript is built along with pgAdmin and can be accessed through the pgAdmin Query Tool. It can also be built as a command-line program. This document explains how to build and use the command-line interface.

The command-line interface is in xtra/pgscript (this directory) while main pgScript source code is in pgadmin/pgscript.

pgScript install

Requirements

Linux or MinGW environment (should work on MacOS)

g++.exe (GCC) >= 3.4.x

wxWidgets >= 2.8.7

PostgreSQL (libpq) >= 8.0

Basic install

Go to the root directory of pgAdmin and enter the following command:

./configure

Go to the xtra/pgscript directory and enter the following command:

make
./bin/pgScript

You can possibly install pgScript binary:

make install

Usage

Synopsis

pgScript -h host [-p port] -d database -U username [-W password] [-e encoding] inputfile

The output is UTF8-encoded.

Options

-h host

Database server host to connect to e.g 127.0.0.1

-p port

Database server port number (default: 5432)

-d database

Database to connect to

-U username

Username to use for connecting to the database server

-W password

Password to use for connecting to the database server (default: nothing)

-e encoding

Encoding of file e.g utf-8, iso-8859-1 (default: system encoding)

pgScript input file

Path to the file to parse with pgScript (.pgs file)

Example

pgScript -h 127.0.0.1 -U postgres -W postgres -d testbase -e "utf-8" script.pgs

This connects to the database 127.0.0.1:5432/testbase with the credentials postgres/postgres and parses the UTF-8 encoded file script.pgs. The output is written on screen and is UTF-8 encoded.

pgScript scripting language reference

Refer to pgScript help page in pgAdmin: pgscript.html.