___ _ _
_ __ __ _/ __| __ _ _(_)_ __| |_
| '_ \/ _` \__ \/ _| '_| | '_ \ _|
| .__/\__, |___/\__|_| |_| .__/\__|
|_| |___/ |_|
Table of Contents
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.
Linux or MinGW environment (should work on MacOS)
g++.exe (GCC) >= 3.4.x
wxWidgets >= 2.8.7
PostgreSQL (libpq) >= 8.0
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
pgScript -h host [-p port] -d database -U username [-W password] [-e encoding] inputfile
The output is UTF8-encoded.
hostDatabase server host to connect to e.g 127.0.0.1
portDatabase server port number (default: 5432)
databaseDatabase to connect to
usernameUsername to use for connecting to the database server
passwordPassword to use for connecting to the database server
(default: nothing)
encodingEncoding of file e.g utf-8, iso-8859-1 (default: system
encoding)
pgScript input
filePath to the file to parse with pgScript (.pgs file)
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.
Refer to pgScript help page in pgAdmin: pgscript.html.