Discover Packages
github.com/joncrlsn/pgcp
command
module
Version:
v0.0.0-...-daeca31
Opens a new window with list of versions in this module.
Published: Apr 9, 2016
License: MIT
Opens a new window with license information.
Imports: 10
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
README
¶
pgcp - PostgreSQL table copy
Written in GoLang, this utility copies some or all rows of a Postgres database table as INSERT or UPDATE statements. All columns are included in the INSERT or UPDATE statements.
Suggestions and modifications to make this more useful and "idiomatic Go" will be appreciated.
download
osx
linux
windows
usage
pgcp [database flags] <genType> <tableName> [idColumn] <whereClause>
examples
pgcp -U dbuser -h 10.10.41.55 -d userdb INSERT users "where user_id < 10"
pgcp -U dbuser -h 10.10.41.55 -d userdb UPDATE users user_id "where user_id < 10"
options/flags (these mostly match psql arguments):
program flag/option
explanation
-V, --version
prints the version of pgcp being run
-?, --help
prints a summary of the commands accepted by pgcp
-U, --user
user in postgres to execute the commands
-h, --host
host name where database is running (default is localhost)
-p, --port
port database is listening on (default is 5432)
-d, --dbname
database name
-O, --options
postgresql connection options (like sslmode=disable)
-w, --no-password
Never issue a db password prompt
-W, --password
Force a db password prompt
-o, --output-file
Send output to the given file
argument
explanation
<genType>
type of SQL to generate: INSERT or UPDATE. (case insensitive)
<tableName>
name of table to be outputted (fully or partially)
[idColumn]
only specify when genType is UPDATE
<whereClause>
specifies which rows to copy. example: "WHERE user_id < 100 AND username IS NOT NULL"
database connection options
Use environment variables (see table below)
Program flags (overrides environment variables)
~/.pgpass file
Note that if password is not specified, you will be prompted.
optional database environment variables
name
explanation
PGHOST
host name where database is running (matches psql)
PGPORT
port database is listening on (default is 5432) (matches psql)
PGDATABASE
name of database you want to copy (matches psql)
PGUSER
user in postgres you'll be executing the queries as (matches psql)
PGPASSWORD
password for the user (matches psql)
PGOPTION
one or more database options (like sslmode=disable)
todo
Fix bug where Ctrl-C in the password entry field messes up the console. fixed in version 1.0.5
Fix -? and -V flags that are not working. Fixed in version 1.0.6
Add --output-file (-o) flag Added in version 1.0.6
Convert positional arguments to program options/flags? How important is this to people?
Improve the accuracy of parsing ~/.pgpass
Expand ▾
Collapse ▴
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.