- createuser: Creation of user "username" failed.
+ createuser: creation of user "username" failed
Something went wrong. The user was not created.
- dropuser: Deletion of user "username" failed.
+ dropuser: deletion of user "username" failed
Something went wrong. The user was not removed.
- The command form \d? is identical, but any comments
+ The command form \d+ is identical, but any comments
associated with the table columns are shown as well.
Lists all available aggregate functions, together with the data type they operate on.
If pattern
(a regular expression) is specified, only matching aggregates are shown.
- If the alternative command form \da? is used,
- comments are listed for each function as well. The command form
- \da+ will show more information about each aggregate
- function, which is usually not of general interest.
If pattern
(a regular expression) is specified, only matching functions are shown.
If the form \df+ is used, additional information about
- each function is shown. Comments for each function can be shown with
- the \df? form.
+ each function, including language and description is shown.
If pattern is specified,
it is a regular expression restricts the listing to those objects
- whose name matches. If one appends a ?
to the command name,
+ whose name matches. If one appends a +
to the command name,
each object is listed with its associated description, if any.
interpretation of the backslash as a new command, you might also
wish to quote the argument.)
- If the form \do? is used, comments are listed for
- each operator.
-
Lists all data types or only those that match pattern.
- The command forms \dT+ and \dT? show extra information
- and the associated descriptions of the types, respectively.
+ The command form \dT+ shows extra information.
List all the databases in the server as well as their owners. Append a
- ?
(question mark) to the command name to see any descriptions
+ +
to the command name to see any descriptions
for the databases as well. If your
PostgreSQL
installation was
compiled with multibyte encoding support, the encoding scheme of each
Shows a list of all
PostgreSQL large
objects currently stored in the database along with their owners.
- Append a question mark to the command name (\lo_list?) to
- see the the associated comments as well.
If so configured,
psql understands both standard
- Unix short options, and
GNU-style long options. Since the
- latter are not available on all systems, you are advised to consider carefully
- whether to use them, if you are writing scripts, etc. For support on the
-
PostgreSQL mailing lists, you are asked to only
- use the standard short options.
+ Unix short options, and
GNU-style long options. The latter
+ are not available on all systems, so you are advised to consider carefully
+ whether to use them.
- -F, --field-sep separator
+ -F, --field-separator separator
Use separator as the field separator.
- -o, --out filename
+ -o, --output filename
Put all query output into file filename.
Specifies that
psql should do its work quietly.
- By default, it prints welcome messages, various informational output and
- prompts for each query.
+ By default, it prints welcome messages and various informational output.
If this option is used, none of this happens. This is useful with the
option. Within
psql you can
also set the quiet variable to achieve the same effect.
-V, --version
- Shows version information about
psql and your
-
PostgreSQL database server, if it could be reached.
-
-
- The output looks similar to this:
-~$ psql -V
-Server: PostgreSQL 6.5.2 on i586-pc-linux-gnu, compiled by egcs
-psql 6.6.0 on i586-pc-linux-gnu, compiled by gcc 2.8.1 (Oct 27 1999 15:15:04), long options,
-readline, history, locale, assert checks
-
- The Server
line is identical to the one returned by the
- backend function version() and thus might vary
- if you query different servers by using different connection
- options.
-
-
- The
psql
line is compiled into the
psql
- binary. It shows you which
PostgreSQL release
- it was distributed with and what optional features were compiled into it.
- Although in general (as in the example above) you can use
psql
- and database servers from different versions (if they don't differ too much)
- this is not recommended or
- even necessary. The optional features indicate only
psql's
- capabilities but if
psql was configured with
- the same source tree as the rest of the distribution, it gives you an
- indication about other parts of the installation as well.
+ Shows the
psql version.
-
-
History and Lineage
-
-
psql first appeared in
Postgres95
- to complement and later replace the
monitor program. (You see this
- name here or there in really old files. The author has never had the pleasure to use this
- program though.) An uncountable number of people have added features since to reflect
- the enhancements in the actual database server.
-
-
- The present version is the result of a major clean-up and re-write in 1999 by
-
Peter Eisentraut in preparation for release 7.0.
- Many people had again contributed their ideas. A bunch of features were stolen
- from various shells (in case you hadn't noticed), in particular
-
-
-
if (status == CMD_UNKNOWN)
{
- fprintf(stderr, "Unrecognized command: \\%s. Try \\? for help.\n", cmd);
+ if (pset->cur_cmd_interactive)
+ fprintf(stderr, "Invalid command \\%s. Try \\? for help.\n", cmd);
+ else
+ fprintf(stderr, "%s: invalid command \\%s", pset->progname, cmd);
status = CMD_ERROR;
}
else if (cmd[0] == 'd')
{
bool show_verbose = strchr(cmd, '+') ? true : false;
- bool show_desc = strchr(cmd, '?') ? true : false;
switch (cmd[1])
{
case '\0':
case '?':
if (options[0])
- success = describeTableDetails(options[0], pset, show_desc);
+ success = describeTableDetails(options[0], pset, show_verbose);
else
/* standard listing of interesting things */
- success = listTables("tvs", NULL, pset, show_desc);
+ success = listTables("tvs", NULL, pset, show_verbose);
break;
case 'a':
- success = describeAggregates(options[0], pset, show_verbose, show_desc);
+ success = describeAggregates(options[0], pset);
break;
case 'd':
success = objectDescription(options[0], pset);
break;
case 'f':
- success = describeFunctions(options[0], pset, show_verbose, show_desc);
+ success = describeFunctions(options[0], pset, show_verbose);
break;
case 'l':
- success = do_lo_list(pset, show_desc);
+ success = do_lo_list(pset);
break;
case 'o':
- success = describeOperators(options[0], pset, show_verbose, show_desc);
+ success = describeOperators(options[0], pset);
break;
case 'p':
success = permissionsList(options[0], pset);
break;
case 'T':
- success = describeTypes(options[0], pset, show_verbose, show_desc);
+ success = describeTypes(options[0], pset, show_verbose);
break;
case 't':
case 'v':
case 's':
case 'S':
if (cmd[1] == 'S' && cmd[2] == '\0')
- success = listTables("Stvs", NULL, pset, show_desc);
+ success = listTables("Stvs", NULL, pset, show_verbose);
else
- success = listTables(&cmd[1], options[0], pset, show_desc);
+ success = listTables(&cmd[1], options[0], pset, show_verbose);
break;
default:
status = CMD_UNKNOWN;
{
if (!options[0])
{
- fputs("Usage: \\i \n", stderr);
+ if (pset->cur_cmd_interactive)
+ fprintf(stderr, "\\%s: missing required argument\n", cmd);
+ else
+ fprintf(stderr, "%s: \\%s: missing required argument", pset->progname, cmd);
success = false;
}
else
/* \l is list databases */
else if (strcmp(cmd, "l") == 0 || strcmp(cmd, "list") == 0)
success = listAllDbs(pset, false);
- else if (strcmp(cmd, "l?") == 0 || strcmp(cmd, "list?") == 0)
+ else if (strcmp(cmd, "l+") == 0 || strcmp(cmd, "list+") == 0)
success = listAllDbs(pset, true);
{
if (!options[1])
{
- fputs("Usage: \\lo_export \n", stderr);
+ if (pset->cur_cmd_interactive)
+ fprintf(stderr, "\\%s: missing required argument", cmd);
+ else
+ fprintf(stderr, "%s: \\%s: missing required argument", pset->progname, cmd);
success = false;
}
else
{
if (!options[0])
{
- fputs("Usage: \\lo_import []\n", stderr);
+ if (pset->cur_cmd_interactive)
+ fprintf(stderr, "\\%s: missing required argument", cmd);
+ else
+ fprintf(stderr, "%s: \\%s: missing required argument", pset->progname, cmd);
success = false;
}
else
}
else if (strcmp(cmd + 3, "list") == 0)
- success = do_lo_list(pset, false);
- else if (strcmp(cmd + 3, "list?") == 0)
- success = do_lo_list(pset, true);
+ success = do_lo_list(pset);
else if (strcmp(cmd + 3, "unlink") == 0)
{
if (!options[0])
{
- fputs("Usage: \\lo_unlink \n", stderr);
+ if (pset->cur_cmd_interactive)
+ fprintf(stderr, "\\%s: missing required argument", cmd);
+ else
+ fprintf(stderr, "%s: \\%s: missing required argument", pset->progname, cmd);
success = false;
}
else
{
if (query_buf && query_buf->len > 0)
puts(query_buf->data);
- else if (!GetVariableBool(pset->vars, "quiet"))
+ else if (!quiet)
puts("Query buffer is empty.");
fflush(stdout);
}
{
if (!options[0])
{
- fputs("Usage: \\pset
[]\n", stderr);
+ if (pset->cur_cmd_interactive)
+ fprintf(stderr, "\\%s: missing required argument", cmd);
+ else
+ fprintf(stderr, "%s: \\%s: missing required argument", pset->progname, cmd);
success = false;
}
else
{
if (!SetVariable(pset->vars, options[0], options[1]))
{
- fprintf(stderr, "Set variable failed.\n");
+ if (pset->cur_cmd_interactive)
+ fprintf(stderr, "\\%s: failed\n", cmd);
+ else
+ fprintf(stderr, "%s: \\%s: failed\n", pset->progname, cmd);
+
success = false;
}
}
if (!options[0])
{
- fprintf(stderr, "Usage: \\%s \n", cmd);
+ if (pset->cur_cmd_interactive)
+ fprintf(stderr, "\\%s: missing required argument", cmd);
+ else
+ fprintf(stderr, "%s: \\%s: missing required argument", pset->progname, cmd);
success = false;
}
else
*/
if (!pset->db || PQstatus(pset->db) == CONNECTION_BAD)
{
- fprintf(stderr, "Could not establish database connection.\n%s", PQerrorMessage(pset->db));
- PQfinish(pset->db);
- if (!oldconn || !pset->cur_cmd_interactive)
- { /* we don't want unpredictable things to
- * happen in scripting mode */
- fputs("Terminating.\n", stderr);
+ if (pset->cur_cmd_interactive)
+ {
+ fprintf(stderr, "\\connect: %s", PQerrorMessage(pset->db));
+ PQfinish(pset->db);
+ if (oldconn)
+ {
+ fputs("Previous connection kept\n", stderr);
+ pset->db = oldconn;
+ }
+ else
+ pset->db = NULL;
+ }
+ else
+ {
+ /* we don't want unpredictable things to
+ * happen in scripting mode */
+ fprintf(stderr, "%s: \\connect: %s", pset->progname, PQerrorMessage(pset->db));
+ PQfinish(pset->db);
if (oldconn)
PQfinish(oldconn);
- pset->db = NULL;
- }
- else
- {
- fputs("Keeping old connection.\n", stderr);
- pset->db = oldconn;
+ pset->db = NULL;
}
}
else
printf("You are now connected to database %s.\n", dbparam);
else if (dbparam != new_dbname) /* no new db */
printf("You are now connected as new user %s.\n", new_user);
- else
-/* both new */
+ else /* both new */
printf("You are now connected to database %s as user %s.\n",
PQdb(pset->db), PQuser(pset->db));
}
static bool
do_edit(const char *filename_arg, PQExpBuffer query_buf)
{
- char fnametmp[64];
+ char fnametmp[MAXPGPATH];
FILE *stream;
const char *fname;
bool error = false;
/* make a temp file to edit */
#ifndef WIN32
mode_t oldumask;
+ const char *tmpdirenv = getenv("TMPDIR");
- sprintf(fnametmp, "/tmp/psql.edit.%ld.%ld", (long) geteuid(), (long) getpid());
+ sprintf(fnametmp, "%s/psql.edit.%ld.%ld",
+ tmpdirenv ? tmpdirenv : "/tmp",
+ (long) geteuid(), (long) getpid());
#else
GetTempFileName(".", "psql", 0, fnametmp);
#endif
break;
case PGRES_COPY_OUT:
- if (pset->cur_cmd_interactive && !GetVariableBool(pset->vars, "quiet"))
- puts("Copy command returns:");
-
success = handleCopyOut(pset->db, pset->queryFout);
break;
case PGRES_FATAL_ERROR:
case PGRES_BAD_RESPONSE:
success = false;
- fputs(PQerrorMessage(pset->db), pset->queryFout);
+ fputs(PQerrorMessage(pset->db), stderr);
break;
}
if (PQstatus(pset->db) == CONNECTION_BAD)
{
+ if (!pset->cur_cmd_interactive)
+ {
+ fprintf(stderr, "%s: connection to server was lost", pset->progname);
+ exit(EXIT_BADCONN);
+ }
fputs("The connection to the server was lost. Attempting reset: ", stderr);
PQreset(pset->db);
if (PQstatus(pset->db) == CONNECTION_BAD)
* parse_slash_copy
* -- parses \copy command line
*
- * Accepted syntax: \copy [binary] table|"table" [with oids] from|to filename|'filename' using delimiters ['']
+ * Accepted syntax: \copy [binary] table|"table" [with oids] from|to filename|'filename' using delimiters [''] [ with null as 'string' ]
* (binary is not here yet)
*
* returns a malloc'ed structure with the options, or NULL on parsing error
bool binary;
bool oids;
char *delim;
+ char *null;
};
free(ptr->table);
free(ptr->file);
free(ptr->delim);
+ free(ptr->null);
free(ptr);
}
static struct copy_options *
-parse_slash_copy(const char *args)
+parse_slash_copy(const char *args, PsqlSettings *pset)
{
struct copy_options *result;
char *line;
error = true;
else
{
- if (!quote && strcasecmp(token, "binary") == 0)
+#ifdef NOT_USED
+ /* this is not implemented yet */
+ if (!quote && strcasecmp(token, "binary") == 0)
{
result->binary = true;
token = strtokx(NULL, " \t", "\"", '\\', "e, NULL);
error = true;
}
if (token)
+#endif
result->table = xstrdup(token);
}
token = strtokx(NULL, " \t", NULL, '\\', NULL, NULL);
if (token)
{
- if (strcasecmp(token, "using") != 0)
- error = true;
- else
+ if (strcasecmp(token, "using") == 0)
{
token = strtokx(NULL, " \t", NULL, '\\', NULL, NULL);
if (!token || strcasecmp(token, "delimiters") != 0)
{
token = strtokx(NULL, " \t", "'", '\\', NULL, NULL);
if (token)
+ {
result->delim = xstrdup(token);
+ token = strtokx(NULL, " \t", NULL, '\\', NULL, NULL);
+ }
else
error = true;
}
}
+
+ if (!error && token)
+ {
+ if (strcasecmp(token, "with") == 0)
+ {
+ token = strtokx(NULL, " \t", NULL, '\\', NULL, NULL);
+ if (!token || strcasecmp(token, "null") != 0)
+ error = true;
+ else
+ {
+ token = strtokx(NULL, " \t", NULL, '\\', NULL, NULL);
+ if (!token || strcasecmp(token, "as") != 0)
+ error = true;
+ else
+ {
+ token = strtokx(NULL, " \t", "'", '\\', NULL, NULL);
+ if (token)
+ result->null = xstrdup(token);
+ }
+ }
+ }
+ }
}
}
if (error)
{
- fputs("Parse error at ", stderr);
+ if (!pset->cur_cmd_interactive)
+ fprintf(stderr, "%s: ", pset->progname);
+ fputs("\\copy: parse error at ", stderr);
if (!token)
- fputs("end of line.", stderr);
+ fputs("end of line", stderr);
else
- fprintf(stderr, "'%s'.", token);
+ fprintf(stderr, "'%s'", token);
fputs("\n", stderr);
free(result);
return NULL;
bool success;
/* parse options */
- options = parse_slash_copy(args);
+ options = parse_slash_copy(args, pset);
if (!options)
return false;
strcpy(query, "COPY ");
if (options->binary)
- fputs("Warning: \\copy binary is not implemented. Resorting to text output.\n", stderr);
-/* strcat(query, "BINARY "); */
+ strcat(query, "BINARY ");
strcat(query, "\"");
strncat(query, options->table, NAMEDATALEN);
if (options->delim)
{
-
- /*
- * backend copy only uses the first character here, but that might
- * be the escape backslash (makes me wonder though why it's called
- * delimiterS)
- */
- strncat(query, " USING DELIMITERS '", 2);
+ strcat(query, " USING DELIMITERS '");
strcat(query, options->delim);
strcat(query, "'");
}
if (!copystream)
{
+ if (!pset->cur_cmd_interactive)
+ fprintf(stderr, "%s: ", pset->progname);
fprintf(stderr,
- "Unable to open file %s which to copy: %s\n",
- options->from ? "from" : "to", strerror(errno));
+ "unable to open file %s: %s\n",
+ options->file, strerror(errno));
free_copy_options(options);
return false;
}
break;
default:
success = false;
- fprintf(stderr, "Unexpected response (%d)\n", PQresultStatus(result));
+ if (!pset->cur_cmd_interactive)
+ fprintf(stderr, "%s: ", pset->progname);
+ fprintf(stderr, "\\copy: unexpected response (%d)\n", PQresultStatus(result));
}
PQclear(result);
if (!GetVariable(pset->vars, "quiet"))
{
if (success)
- puts("Successfully copied.");
+ puts("Successfully copied");
else
- puts("Copy failed.");
+ puts("Copy failed");
}
fclose(copystream);
* Handlers for various slash commands displaying some sort of list
* of things in the database.
*
- * If you add something here, consider this:
- * - If (and only if) the variable "description" is set, the description/
- * comment for the object should be displayed.
- * - Try to format the query to look nice in -E output.
+ * If you add something here, try to format the query to look nice in -E output.
*----------------
*/
* takes an optional regexp to match specific aggregates by name
*/
bool
-describeAggregates(const char *name, PsqlSettings *pset, bool verbose, bool desc)
+describeAggregates(const char *name, PsqlSettings *pset)
{
char buf[384 + 2 * REGEXP_CUTOFF];
PGresult *res;
* types ones that work on all
*/
strcpy(buf,
- "SELECT a.aggname AS \"Name\", t.typname AS \"Type\"");
- if (verbose)
- strcat(buf, " ,u.usename as \"Owner\"");
- if (desc)
- strcat(buf, ",\n obj_description(a.oid) as \"Description\"");
- strcat(buf, !verbose ?
- ("\nFROM pg_aggregate a, pg_type t\n"
- "WHERE a.aggbasetype = t.oid\n") :
- ("\nFROM pg_aggregate a, pg_type t, pg_user u\n"
- "WHERE a.aggbasetype = t.oid AND a.aggowner = u.usesysid\n")
- );
+ "SELECT a.aggname AS \"Name\", t.typname AS \"Type\",\n"
+ " obj_description(a.oid) as \"Description\"\n"
+ "FROM pg_aggregate a, pg_type t\n"
+ "WHERE a.aggbasetype = t.oid\n"
+ );
if (name)
{
strcat(buf,
"UNION\n"
- "SELECT a.aggname AS \"Name\", '(all types)' as \"Type\"");
- if (verbose)
- strcat(buf, " ,u.usename as \"Owner\"");
- if (desc)
- strcat(buf,
- ",\n obj_description(a.oid) as \"Description\"");
- strcat(buf, !verbose ?
- ("\nFROM pg_aggregate a\n"
- "WHERE a.aggbasetype = 0\n") :
- ("\nFROM pg_aggregate a, pg_user u\n"
- "WHERE a.aggbasetype = 0 AND a.aggowner = u.usesysid\n")
- );
+ "SELECT a.aggname AS \"Name\", '(all types)' as \"Type\",\n"
+ " obj_description(a.oid) as \"Description\"\n"
+ "FROM pg_aggregate a\n"
+ "WHERE a.aggbasetype = 0\n"
+ );
+
if (name)
{
strcat(buf, " AND a.aggname ~* '");
if (!res)
return false;
- myopt.topt.tuples_only = false;
myopt.nullPrint = NULL;
myopt.title = "List of aggregates";
* Takes an optional regexp to narrow down the function name
*/
bool
-describeFunctions(const char *name, PsqlSettings *pset, bool verbose, bool desc)
+describeFunctions(const char *name, PsqlSettings *pset, bool verbose)
{
char buf[384 + REGEXP_CUTOFF];
PGresult *res;
* arguments, but have no types defined for those arguments
*/
strcpy(buf,
- "SELECT t.typname as \"Result\", p.proname as \"Function\",\n"
+ "SELECT t.typname as \"Result\", p.proname as \"Function\",\n"
" oidvectortypes(p.proargtypes) as \"Arguments\"");
if (verbose)
- strcat(buf, ",\n u.usename as \"Owner\", l.lanname as \"Language\", p.prosrc as \"Source\"");
- if (desc)
- strcat(buf, ",\n obj_description(p.oid) as \"Description\"");
+ strcat(buf, ",\n u.usename as \"Owner\", l.lanname as \"Language\", p.prosrc as \"Source\",\n"
+ " obj_description(p.oid) as \"Description\"");
if (!verbose)
strcat(buf,
if (!res)
return false;
- myopt.topt.tuples_only = false;
myopt.nullPrint = NULL;
myopt.title = "List of functions";
* describe types
*/
bool
-describeTypes(const char *name, PsqlSettings *pset, bool verbose, bool desc)
+describeTypes(const char *name, PsqlSettings *pset, bool verbose)
{
char buf[256 + REGEXP_CUTOFF];
PGresult *res;
strcpy(buf, "SELECT t.typname AS \"Type\"");
if (verbose)
- strcat(buf,
- ",\n (CASE WHEN t.typlen=-1 THEN 'var'::text ELSE t.typlen::text END) as \"Length\""
- ",\n u.usename as \"Owner\""
- );
- /*
- * Let's always show descriptions for this. There is room.
- * bjm 1999/12/31
- */
- strcat(buf, ",\n obj_description(t.oid) as \"Description\"");
+ strcat(buf, ",\n (CASE WHEN t.typlen = -1 THEN 'var'::text ELSE t.typlen::text END) as \"Size\"");
+ strcat(buf, ",\n obj_description(t.oid) as \"Description\"");
/*
* do not include array types (start with underscore),
* do not include user relations (typrelid!=0)
*/
- strcat(buf, !verbose ?
- ("\nFROM pg_type t\n"
- "WHERE t.typrelid = 0 AND t.typname !~ '^_.*'\n") :
- ("\nFROM pg_type t, pg_user u\n"
- "WHERE t.typrelid = 0 AND t.typname !~ '^_.*' AND t.typowner = u.usesysid\n")
- );
+ strcat(buf, "\nFROM pg_type t\nWHERE t.typrelid = 0 AND t.typname !~ '^_.*'\n");
if (name)
{
if (!res)
return false;
- myopt.topt.tuples_only = false;
myopt.nullPrint = NULL;
myopt.title = "List of types";
/* \do
*/
bool
-describeOperators(const char *name, PsqlSettings *pset, bool verbose, bool desc)
+describeOperators(const char *name, PsqlSettings *pset)
{
char buf[1536 + 3 * REGEXP_CUTOFF];
PGresult *res;
printQueryOpt myopt = pset->popt;
- /* Not used right now. Maybe later. */
- (void)verbose;
-
- /* FIXME: Use outer joins here when ready */
-
strcpy(buf,
- "SELECT o.oprname AS \"Op\",\n"
+ "SELECT o.oprname AS \"Op\",\n"
" t1.typname AS \"Left arg\",\n"
" t2.typname AS \"Right arg\",\n"
- " t0.typname AS \"Result\"");
- if (desc)
- strcat(buf, ",\n obj_description(p.oid) as \"Description\"");
- strcat(buf,
- "\nFROM pg_proc p, pg_type t0,\n"
+ " t0.typname AS \"Result\",\n"
+ " obj_description(p.oid) as \"Description\"\n"
+ "FROM pg_proc p, pg_type t0,\n"
" pg_type t1, pg_type t2,\n"
" pg_operator o\n"
"WHERE p.prorettype = t0.oid AND\n"
"SELECT o.oprname as \"Op\",\n"
" ''::name AS \"Left arg\",\n"
" t1.typname AS \"Right arg\",\n"
- " t0.typname AS \"Result\"");
- if (desc)
- strcat(buf, ",\n obj_description(p.oid) as \"Description\"");
- strcat(buf, "\nFROM pg_operator o, pg_proc p, pg_type t0, pg_type t1\n"
+ " t0.typname AS \"Result\",\n"
+ " obj_description(p.oid) as \"Description\"\n"
+ "FROM pg_operator o, pg_proc p, pg_type t0, pg_type t1\n"
"WHERE RegprocToOid(o.oprcode) = p.oid AND\n"
" o.oprresult = t0.oid AND\n"
" o.oprkind = 'l' AND\n"
"SELECT o.oprname as \"Op\",\n"
" t1.typname AS \"Left arg\",\n"
" ''::name AS \"Right arg\",\n"
- " t0.typname AS \"Result\"");
- if (desc)
- strcat(buf, ",\n obj_description(p.oid) as \"Description\"");
- strcat(buf, "\nFROM pg_operator o, pg_proc p, pg_type t0, pg_type t1\n"
+ " t0.typname AS \"Result\",\n"
+ " obj_description(p.oid) as \"Description\"\n"
+ "FROM pg_operator o, pg_proc p, pg_type t0, pg_type t1\n"
"WHERE RegprocToOid(o.oprcode) = p.oid AND\n"
" o.oprresult = t0.oid AND\n"
" o.oprkind = 'r' AND\n"
if (!res)
return false;
- myopt.topt.tuples_only = false;
myopt.nullPrint = NULL;
myopt.title = "List of operators";
listAllDbs(PsqlSettings *pset, bool desc)
{
PGresult *res;
- char buf[256];
+ char buf[512];
printQueryOpt myopt = pset->popt;
strcpy(buf,
- "SELECT pg_database.datname as \"Database\",\n"
+ "SELECT pg_database.datname as \"Database\",\n"
" pg_user.usename as \"Owner\"");
#ifdef MULTIBYTE
strcat(buf,
if (desc)
strcat(buf, ",\n obj_description(pg_database.oid) as \"Description\"\n");
strcat(buf, "FROM pg_database, pg_user\n"
- "WHERE pg_database.datdba = pg_user.usesysid\n"
- "ORDER BY \"Database\"");
+ "WHERE pg_database.datdba = pg_user.usesysid\n");
+
+ /* Also include databases that have no valid owner. */
+ strcat(buf, "\nUNION\n\n");
+
+ strcat(buf,
+ "SELECT pg_database.datname as \"Database\",\n"
+ " NULL as \"Owner\"");
+#ifdef MULTIBYTE
+ strcat(buf,
+ ",\n pg_database.encoding as \"Encoding\"");
+#endif
+ if (desc)
+ strcat(buf, ",\n obj_description(pg_database.oid) as \"Description\"\n");
+ strcat(buf, "FROM pg_database\n"
+ "WHERE pg_database.datdba NOT IN (SELECT usesysid FROM pg_user)\n");
+
+ strcat(buf, "ORDER BY \"Database\"");
res = PSQLexec(pset, buf);
if (!res)
return false;
- myopt.topt.tuples_only = false;
myopt.nullPrint = NULL;
myopt.title = "List of databases";
if (!res)
return false;
- if (PQntuples(res) == 0)
- fputs("Couldn't find any tables.\n", pset->queryFout);
- else
- {
- myopt.topt.tuples_only = false;
- myopt.nullPrint = NULL;
- sprintf(descbuf, "Access permissions for database \"%s\"", PQdb(pset->db));
- myopt.title = descbuf;
+ myopt.nullPrint = NULL;
+ sprintf(descbuf, "Access permissions for database \"%s\"", PQdb(pset->db));
+ myopt.title = descbuf;
- printQuery(res, &myopt, pset->queryFout);
- }
+ printQuery(res, &myopt, pset->queryFout);
PQclear(res);
return true;
-
/*
* Get object comments
*
descbuf[0] = '\0';
/* Aggregate descriptions */
- strcat(descbuf, "SELECT DISTINCT a.aggname as \"Name\", 'aggregate'::text as \"What\", d.description as \"Description\"\n"
+ strcat(descbuf, "SELECT DISTINCT a.aggname as \"Name\", 'aggregate'::text as \"Object\", d.description as \"Description\"\n"
"FROM pg_aggregate a, pg_description d\n"
"WHERE a.oid = d.objoid\n");
if (object)
/* Function descriptions (except in/outs for datatypes) */
strcat(descbuf, "\nUNION ALL\n\n");
- strcat(descbuf, "SELECT DISTINCT p.proname as \"Name\", 'function'::text as \"What\", d.description as \"Description\"\n"
+ strcat(descbuf, "SELECT DISTINCT p.proname as \"Name\", 'function'::text as \"Object\", d.description as \"Description\"\n"
"FROM pg_proc p, pg_description d\n"
"WHERE p.oid = d.objoid AND (p.pronargs = 0 or oidvectortypes(p.proargtypes) != '')\n");
if (object)
/* Operator descriptions */
strcat(descbuf, "\nUNION ALL\n\n");
- strcat(descbuf, "SELECT DISTINCT o.oprname as \"Name\", 'operator'::text as \"What\", d.description as \"Description\"\n"
+ strcat(descbuf, "SELECT DISTINCT o.oprname as \"Name\", 'operator'::text as \"Object\", d.description as \"Description\"\n"
"FROM pg_operator o, pg_description d\n"
/* must get comment via associated function */
"WHERE RegprocToOid(o.oprcode) = d.objoid\n");
/* Type description */
strcat(descbuf, "\nUNION ALL\n\n");
- strcat(descbuf, "SELECT DISTINCT t.typname as \"Name\", 'type'::text as \"What\", d.description as \"Description\"\n"
+ strcat(descbuf, "SELECT DISTINCT t.typname as \"Name\", 'type'::text as \"Object\", d.description as \"Description\"\n"
"FROM pg_type t, pg_description d\n"
"WHERE t.oid = d.objoid\n");
if (object)
/* Relation (tables, views, indices, sequences) descriptions */
strcat(descbuf, "\nUNION ALL\n\n");
- strcat(descbuf, "SELECT DISTINCT c.relname as \"Name\", 'relation'::text||'('||c.relkind||')' as \"What\", d.description as \"Description\"\n"
+ strcat(descbuf, "SELECT DISTINCT c.relname as \"Name\", 'relation'::text||'('||c.relkind||')' as \"Object\", d.description as \"Description\"\n"
"FROM pg_class c, pg_description d\n"
"WHERE c.oid = d.objoid\n");
if (object)
/* Rule description (ignore rules for views) */
strcat(descbuf, "\nUNION ALL\n\n");
- strcat(descbuf, "SELECT DISTINCT r.rulename as \"Name\", 'rule'::text as \"What\", d.description as \"Description\"\n"
+ strcat(descbuf, "SELECT DISTINCT r.rulename as \"Name\", 'rule'::text as \"Object\", d.description as \"Description\"\n"
"FROM pg_rewrite r, pg_description d\n"
"WHERE r.oid = d.objoid AND r.rulename !~ '^_RET'\n");
if (object)
/* Trigger description */
strcat(descbuf, "\nUNION ALL\n\n");
- strcat(descbuf, "SELECT DISTINCT t.tgname as \"Name\", 'trigger'::text as \"What\", d.description as \"Description\"\n"
+ strcat(descbuf, "SELECT DISTINCT t.tgname as \"Name\", 'trigger'::text as \"Object\", d.description as \"Description\"\n"
"FROM pg_trigger t, pg_description d\n"
"WHERE t.oid = d.objoid\n");
if (object)
/*
* describeTableDetails (for \d)
*
- * Unfortunately, the information presented here is so complicated that it
+ * Unfortunately, the information presented here is so complicated that it cannot
* be done in a single query. So we have to assemble the printed table by hand
* and pass it to the underlying printTable() function.
*
*/
+
static void *
xmalloc(size_t size)
{
if (PQntuples(res) == 0)
{
if (!GetVariableBool(pset->vars, "quiet"))
- fprintf(stdout, "Did not find any relation named \"%s\".\n", name);
+ fprintf(stderr, "Did not find any relation named \"%s\".\n", name);
PQclear(res);
return false;
}
* s - sequences
* S - systems tables (~ '^pg_')
* (any order of the above is fine)
+ *
+ * Note: For some reason it always happens to people that their tables have owners
+ * that are no longer in pg_user; consequently they wouldn't show up here. The code
+ * tries to fix this the painful way, hopefully outer joins will be done sometime.
*/
bool
listTables(const char *infotype, const char *name, PsqlSettings *pset, bool desc)
bool showSeq = strchr(infotype, 's') != NULL;
bool showSystem = strchr(infotype, 'S') != NULL;
- char buf[1536 + 4 * REGEXP_CUTOFF];
+ char buf[3072 + 8 * REGEXP_CUTOFF];
PGresult *res;
printQueryOpt myopt = pset->popt;
strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "'\n");
}
+
+ strcat(buf, "UNION\n");
+ strcat(buf, "SELECT c.relname as \"Name\", 'table'::text as \"Type\", NULL as \"Owner\"");
+ if (desc)
+ strcat(buf, ", obj_description(c.oid) as \"Description\"");
+ strcat(buf, "\nFROM pg_class c\n"
+ "WHERE c.relkind = 'r'\n"
+ " AND not exists (select 1 from pg_views where viewname = c.relname)\n"
+ " AND not exists (select 1 from pg_user where usesysid = c.relowner)\n");
+ strcat(buf, showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n");
+ if (name)
+ {
+ strcat(buf, " AND c.relname ~ '");
+ strncat(buf, name, REGEXP_CUTOFF);
+ strcat(buf, "'\n");
+ }
}
/* views */
strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "'\n");
}
+
+ strcat(buf, "UNION\n");
+ strcat(buf, "SELECT c.relname as \"Name\", 'view'::text as \"Type\", NULL as \"Owner\"");
+ if (desc)
+ strcat(buf, ", obj_description(c.oid) as \"Description\"");
+ strcat(buf, "\nFROM pg_class c\n"
+ "WHERE c.relkind = 'r'\n"
+ " AND exists (select 1 from pg_views where viewname = c.relname)\n"
+ " AND not exists (select 1 from pg_user where usesysid = c.relowner)\n");
+ strcat(buf, showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n");
+ if (name)
+ {
+ strcat(buf, " AND c.relname ~ '");
+ strncat(buf, name, REGEXP_CUTOFF);
+ strcat(buf, "'\n");
+ }
}
/* indices, sequences */
strcat(buf, "'S'");
strcat(buf, ")\n");
+ /* ignore large-obj indices */
+ if (showIndices)
+ strcat(buf, " AND (c.relkind != 'i' OR c.relname !~ '^xinx')\n");
+
+ strcat(buf, showSystem ? " AND c.relname ~ '^pg_'\n" : " AND c.relname !~ '^pg_'\n");
+ if (name)
+ {
+ strcat(buf, " AND c.relname ~ '");
+ strncat(buf, name, REGEXP_CUTOFF);
+ strcat(buf, "'\n");
+ }
+
+ strcat(buf, "UNION\n");
+ strcat(buf,
+ "SELECT c.relname as \"Name\",\n"
+ " (CASE WHEN relkind = 'S' THEN 'sequence'::text ELSE 'index'::text END) as \"Type\",\n"
+ " NULL as \"Owner\""
+ );
+ if (desc)
+ strcat(buf, ", obj_description(c.oid) as \"Description\"");
+ strcat(buf, "\nFROM pg_class c\n"
+ "WHERE not exists (select 1 from pg_user where usesysid = c.relowner) AND relkind in (");
+ if (showIndices && showSeq)
+ strcat(buf, "'i', 'S'");
+ else if (showIndices)
+ strcat(buf, "'i'");
+ else
+ strcat(buf, "'S'");
+ strcat(buf, ")\n");
+
/* ignore large-obj indices */
if (showIndices)
strcat(buf, " AND (c.relkind != 'i' OR c.relname !~ '^xinx')\n");
}
}
- /* real system catalogue tables */
+ /* special system tables */
if (showSystem && showTables)
{
if (buf[0])
strcat(buf, "\nUNION\n\n");
- strcat(buf, "SELECT c.relname as \"Name\", 'system'::text as \"Type\", u.usename as \"Owner\"");
+ strcat(buf, "SELECT c.relname as \"Name\", 'special'::text as \"Type\", u.usename as \"Owner\"");
if (desc)
strcat(buf, ", obj_description(c.oid) as \"Description\"");
strcat(buf, "\nFROM pg_class c, pg_user u\n"
strncat(buf, name, REGEXP_CUTOFF);
strcat(buf, "'\n");
}
+
+ strcat(buf, "UNION\n");
+ strcat(buf, "SELECT c.relname as \"Name\", 'special'::text as \"Type\", NULL as \"Owner\"");
+ if (desc)
+ strcat(buf, ", obj_description(c.oid) as \"Description\"");
+ strcat(buf, "\nFROM pg_class c\n"
+ "WHERE c.relkind = 's'\n"
+ " AND not exists (select 1 from pg_user where usesysid = c.relowner)");
+ if (name)
+ {
+ strcat(buf, " AND c.relname ~ '");
+ strncat(buf, name, REGEXP_CUTOFF);
+ strcat(buf, "'\n");
+ }
}
strcat(buf, "\nORDER BY \"Name\"");
PQclear(res);
return true;
}
-
-
-/* end of file */
#include "settings.h"
/* \da */
-bool describeAggregates(const char *name, PsqlSettings *pset, bool verbose, bool desc);
+bool describeAggregates(const char *name, PsqlSettings *pset);
/* \df */
-bool describeFunctions(const char *name, PsqlSettings *pset, bool verbose, bool desc);
+bool describeFunctions(const char *name, PsqlSettings *pset, bool verbose);
/* \dT */
-bool describeTypes(const char *name, PsqlSettings *pset, bool verbose, bool desc);
+bool describeTypes(const char *name, PsqlSettings *pset, bool verbose);
/* \do */
-bool describeOperators(const char *name, PsqlSettings *pset, bool verbose, bool desc);
+bool describeOperators(const char *name, PsqlSettings *pset);
/* \z (or \dp) */
bool permissionsList(const char *name, PsqlSettings *pset);
/*
* usage
*
- * print out command line arguments and exit
+ * print out command line arguments
*/
#define ON(var) (var ? "on" : "off")
#endif
}
-/* If string begins " here, then it ought to end there to fit on an 80 column terminal> > > > > > > " */
- fprintf(stderr, "Usage: psql [options] [dbname [username]] \n");
- fprintf(stderr, " -A Unaligned table output mode (-P format=unaligned)\n");
- fprintf(stderr, " -c query Run single query (slash commands, too) and exit\n");
+/* If this " is the start of the string then it ought to end there to fit in 80 columns >> " */
+ puts( "This is psql, the PostgreSQL interactive terminal.");
+ puts( "\nUsage:");
+ puts( " psql [options] [dbname [username]]");
+ puts( "\nOptions:");
+ puts( " -A Unaligned table output mode (-P format=unaligned");
+ puts( " -c query Run only single query (or slash command) and exit");
/* Display default database */
env = getenv("PGDATABASE");
if (!env)
env = user;
- fprintf(stderr, " -d dbname Specify database name to connect to (default: %s)\n", env);
+ printf(" -d dbname Specify database name to connect to (default: %s)\n", env);
- fprintf(stderr, " -e Echo all input in non-interactive mode\n");
- fprintf(stderr, " -E Display queries that internal commands generate\n");
- fprintf(stderr, " -f filename Execute queries from file, then exit\n");
- fprintf(stderr, " -F sep Set field separator (default: '" DEFAULT_FIELD_SEP "') (-P fieldsep=)\n");
+ puts( " -e Echo all input in non-interactive mode");
+ puts( " -E Display queries that internal commands generate");
+ puts( " -f filename Execute queries from file, then exit");
+ puts( " -F sep Set field separator (default: \"" DEFAULT_FIELD_SEP "\") (-P fieldsep=)");
/* Display default host */
env = getenv("PGHOST");
- fprintf(stderr, " -h host Specify database server host (default: ");
+ printf(" -h host Specify database server host (default: ");
if (env)
- fprintf(stderr, env);
+ fputs(env, stdout);
else
- fprintf(stderr, "domain socket");
- fprintf(stderr, ")\n");
+ fputs("domain socket", stdout);
+ puts(")");
- fprintf(stderr, " -H HTML table output mode (-P format=html)\n");
- fprintf(stderr, " -l List available databases, then exit\n");
- fprintf(stderr, " -n Do not use readline and history\n");
- fprintf(stderr, " -o filename Send query output to filename (or |pipe)\n");
+ puts( " -H HTML table output mode (-P format=html)");
+ puts( " -l List available databases, then exit");
+ puts( " -n Do not use readline or history");
+ puts( " -o filename Send query output to filename (or |pipe)");
/* Display default port */
env = getenv("PGPORT");
- fprintf(stderr, " -p port Specify database server port (default: %s)\n",
- env ? env : "hardwired");
+ printf(" -p port Specify database server port (default: %s)\n",
+ env ? env : "hardwired");
- fprintf(stderr, " -P var[=arg] Set printing option 'var' to 'arg'. (see \\pset command)\n");
- fprintf(stderr, " -q Run quietly (no messages, no prompts)\n");
- fprintf(stderr, " -s Single step mode (confirm each query)\n");
- fprintf(stderr, " -S Single line mode (newline sends query)\n");
- fprintf(stderr, " -t Don't print headings and row count (-P tuples_only)\n");
- fprintf(stderr, " -T text Set HTML table tag options (e.g., width, border)\n");
- fprintf(stderr, " -u Prompt for username and password (same as \"-U ? -W\")\n");
+ puts( " -P var[=arg] Set printing option 'var' to 'arg' (see \\pset command)");
+ puts( " -q Run quietly (no messages, only query output)");
+ puts( " -s Single step mode (confirm each query)");
+ puts( " -S Single line mode (newline terminates query)");
+ puts( " -t Don't print headings and row count (-P tuples_only)");
+ puts( " -T text Set HTML table tag options (width, border) (-P tableattr=)");
/* Display default user */
env = getenv("PGUSER");
if (!env)
env = user;
- fprintf(stderr, " -U [username] Specifiy username, \"?\"=prompt (default user: %s)\n", env);
+ printf(" -U [username] Specifiy username, \"?\"=prompt (default user: %s)\n", env);
- fprintf(stderr, " -x Turn on expanded table output (-P expanded)\n");
- fprintf(stderr, " -v name=val Set psql variable 'name' to 'value'\n");
- fprintf(stderr, " -V Show version information and exit\n");
- fprintf(stderr, " -W Prompt for password (should happen automatically)\n");
+ puts( " -x Turn on expanded table output (-P expanded)");
+ puts( " -v name=val Set psql variable 'name' to 'value'");
+ puts( " -V Show version information and exit");
+ puts( " -W Prompt for password (should happen automatically)");
- fprintf(stderr, "Consult the documentation for the complete details.\n");
+ puts( "\nFor more information, type \"\\?\" (for internal commands) or \"\\help\"");
+ puts( "(for SQL commands) from within psql, or consult the psql section in the");
+ puts( "PostgreSQL manual, which accompanies the distribution and is also available at");
+ puts( ".");
+ puts( "Report bugs to .");
#ifndef WIN32
if (pw)
fout = stdout;
/* if you add/remove a line here, change the row test above */
- fprintf(fout, " \\? -- help\n");
- fprintf(fout, " \\c[onnect] [dbname|- [user|?]] -- connect to new database (now '%s')\n", PQdb(pset->db));
- fprintf(fout, " \\copy [binary]
[with oids] {from|to} [using delimiters '']\n");
- fprintf(fout, " \\copyright -- show PostgreSQL copyright\n");
- fprintf(fout, " \\d
-- describe table (or view, index, sequence)\n");
- fprintf(fout, " \\d{i|s|t|v|S}-- list only indices/sequences/tables/views/system tables\n");
- fprintf(fout, " \\da -- list aggregates\n");
- fprintf(fout, " \\dd [object] -- list comment for table, type, function, or operator\n");
- fprintf(fout, " \\df -- list functions\n");
- fprintf(fout, " \\do -- list operators\n");
- fprintf(fout, " \\dT -- list data types\n");
- fprintf(fout, " \\e [fname] -- edit the current query buffer or with external editor\n");
- fprintf(fout, " \\echo -- write text to stdout\n");
- fprintf(fout, " \\g [fname] -- send query to backend (and results in or |pipe)\n");
- fprintf(fout, " \\h [cmd] -- help on syntax of sql commands, * for all commands\n");
- fprintf(fout, " \\i -- read and execute queries from filename\n");
- fprintf(fout, " \\l -- list all databases\n");
- fprintf(fout, " \\lo_export, \\lo_import, \\lo_list, \\lo_unlink -- large object operations\n");
- fprintf(fout, " \\o [fname] -- send all query results to , or |pipe\n");
- fprintf(fout, " \\p -- print the content of the current query buffer\n");
- fprintf(fout, " \\pset -- set table output options\n");
- fprintf(fout, " \\q -- quit\n");
- fprintf(fout, " \\qecho -- write text to query output stream (see \\o)\n");
- fprintf(fout, " \\r -- reset (clear) the query buffer\n");
- fprintf(fout, " \\s [fname] -- print history or save it in \n");
- fprintf(fout, " \\set [value] -- set/unset internal variable\n");
- fprintf(fout, " \\t -- don't show table headers or footers (now %s)\n", ON(pset->popt.topt.tuples_only));
- fprintf(fout, " \\x -- toggle expanded output (now %s)\n", ON(pset->popt.topt.expanded));
- fprintf(fout, " \\w -- write current query buffer to a file\n");
- fprintf(fout, " \\z -- list table access permissions\n");
- fprintf(fout, " \\! [cmd] -- shell escape or command\n");
+ fprintf(fout, " \\? help\n");
+ fprintf(fout, " \\c[onnect] [dbname|- [user|?]]\n"
+ " connect to new database (currently '%s')\n", PQdb(pset->db));
+ fprintf(fout, " \\copy ... perform SQL COPY with data stream to the client machine");
+ fprintf(fout, " \\copyright show PostgreSQL usage and distribution terms\n");
+ fprintf(fout, " \\d
describe table (or view, index, sequence)\n");
+ fprintf(fout, " \\d{i|s|t|v|S} list only indices/sequences/tables/views/system tables\n");
+ fprintf(fout, " \\da list aggregates\n");
+ fprintf(fout, " \\dd [object] list comment for table, type, function, or operator\n");
+ fprintf(fout, " \\df list functions\n");
+ fprintf(fout, " \\do list operators\n");
+ fprintf(fout, " \\dT list data types\n");
+ fprintf(fout, " \\e [fname] edit the current query buffer or with external editor\n");
+ fprintf(fout, " \\echo write text to stdout\n");
+ fprintf(fout, " \\g [fname] send query to backend (and results in or |pipe)\n");
+ fprintf(fout, " \\h [cmd] help on syntax of sql commands, * for all commands\n");
+ fprintf(fout, " \\i read and execute queries from filename\n");
+ fprintf(fout, " \\l list all databases\n");
+ fprintf(fout, " \\lo_export, \\lo_import, \\lo_list, \\lo_unlink\n"
+ " large object operations\n");
+ fprintf(fout, " \\o [fname] send all query results to , or |pipe\n");
+ fprintf(fout, " \\p show the content of the current query buffer\n");
+ fprintf(fout, " \\pset [opt] set table output options\n");
+ fprintf(fout, " \\q quit psql\n");
+ fprintf(fout, " \\qecho write text to query output stream (see \\o)\n");
+ fprintf(fout, " \\r reset (clear) the query buffer\n");
+ fprintf(fout, " \\s [fname] print history or save it in \n");
+ fprintf(fout, " \\set [value] set/unset internal variable\n");
+ fprintf(fout, " \\t don't show table headers or footers (currently %s)\n", ON(pset->popt.topt.tuples_only));
+ fprintf(fout, " \\x toggle expanded output (currently %s)\n", ON(pset->popt.topt.expanded));
+ fprintf(fout, " \\w write current query buffer to a file\n");
+ fprintf(fout, " \\z list table access permissions\n");
+ fprintf(fout, " \\! [cmd] shell escape or command\n");
if (usePipe)
{
char left_center_right; /* Which column we're displaying */
int i; /* Index into QL_HELP[] */
- puts("Syntax: \\h or \\help , where is one of the following:");
+ puts("Available help:");
left_center_right = 'L';/* Start with left column */
i = 0;
}
if (left_center_right != 'L')
puts("\n");
- puts("Or type \\h * for a complete description of all commands.");
}
-
else
{
int i;
if (!pset->db)
{
- fputs("You are not connected to a database.\n", stderr);
+ if (!pset->cur_cmd_interactive)
+ fprintf(stderr, "%s: ", pset->progname);
+ fputs("\\lo_export: not connected to a database\n", stderr);
return false;
}
if (!pset->db)
{
- fputs("You are not connected to a database.\n", stderr);
+ if (!pset->cur_cmd_interactive)
+ fprintf(stderr, "%s: ", pset->progname);
+ fputs("\\lo_import: not connected to a database\n", stderr);
return false;
}
if (!pset->db)
{
- fputs("You are not connected to a database.\n", stderr);
+ if (!pset->cur_cmd_interactive)
+ fprintf(stderr, "%s: ", pset->progname);
+ fputs("\\lo_unlink: not connected to a database\n", stderr);
return false;
}
/*
* do_lo_list()
*
- * Show all large objects in database, with comments if desired
+ * Show all large objects in database with comments
*/
bool
-do_lo_list(PsqlSettings *pset, bool desc)
+do_lo_list(PsqlSettings *pset)
{
PGresult *res;
- char buf[512];
+ char buf[1024];
printQueryOpt myopt = pset->popt;
- strcpy(buf, "SELECT usename as \"Owner\", substring(relname from 5) as \"ID\"");
- if (desc)
- strcat(buf, ",\n obj_description(pg_class.oid) as \"Description\"");
- strcat(buf, "\nFROM pg_class, pg_user\n"
+ strcpy(buf,
+ "SELECT usename as \"Owner\", substring(relname from 5) as \"ID\",\n"
+ " obj_description(pg_class.oid) as \"Description\"\n"
+ "FROM pg_class, pg_user\n"
"WHERE usesysid = relowner AND relkind = 'l'\n"
+ "UNION\n"
+ "SELECT NULL as \"Owner\", substring(relname from 5) as \"ID\",\n"
+ " obj_description(pg_class.oid) as \"Description\"\n"
+ "FROM pg_class\n"
+ "WHERE not exists (select 1 from pg_user where usesysid = relowner) AND relkind = 'l'\n"
"ORDER BY \"ID\"");
res = PSQLexec(pset, buf);
bool do_lo_export(PsqlSettings *pset, const char *loid_arg, const char *filename_arg);
bool do_lo_import(PsqlSettings *pset, const char *filename_arg, const char *comment_arg);
bool do_lo_unlink(PsqlSettings *pset, const char *loid_arg);
-bool do_lo_list(PsqlSettings *pset, bool desc);
+bool do_lo_list(PsqlSettings *pset);
#endif /* LARGE_OBJ_H */
}
- /* Setting this will not have effect until next line. (Faster.
- Also think about what happens if there is an error processing
- _this_ command.)
- */
+ /* Setting this will not have effect until next line. */
die_on_error = GetVariableBool(pset->vars, "die_on_error");
/*
if (GetVariableBool(pset->vars, "echo") && !GetVariableBool(pset->vars, "quiet"))
puts("EOF");
else if (pset->cur_cmd_interactive)
- puts(""); /* just newline */
+ putc('\n', stdout); /* just newline */
eof = true;
continue;
free(line);
line = new;
+ len = strlen(new);
continue; /* reparse the just substituted */
}
if (opt_border == 0)
total_w = col_count - 1;
else if (opt_border == 1)
- total_w = col_count * 3 - 2;
+ total_w = col_count * 3 - 1;
else
total_w = col_count * 3 + 1;
*
*
* If the application-wide prompts became NULL somehow, the returned string
- * will be empty (not NULL!). Do not free() the result of this function unless
- * you want trouble.
+ * will be empty (not NULL!).
*--------------------------
*/
const char *
const char *p;
const char *prompt_string;
- if (GetVariable(pset->vars, "quiet"))
- return "";
-
if (status == PROMPT_READY)
prompt_string = GetVariable(pset->vars, "prompt1");
else if (status == PROMPT_CONTINUE || status == PROMPT_SINGLEQUOTE || status == PROMPT_DOUBLEQUOTE || status == PROMPT_COMMENT)
break;
/* DB server port number */
case '>':
- if (pset->db)
- {
- if (PQhost(pset->db))
- strncpy(buf, PQport(pset->db), MAX_PROMPT_SIZE);
- else
- buf[0] = '.';
- }
+ if (pset->db && PQport(pset->db))
+ strncpy(buf, PQport(pset->db), MAX_PROMPT_SIZE);
break;
/* DB server user name */
case 'n':
* startup? */
Oid lastOid; /* saves oid from insert command
because people want it so badly */
+ char *progname; /* in case you renamed psql */
} PsqlSettings;
process_psqlrc(PsqlSettings *pset);
static void
-showVersion(PsqlSettings *pset);
+showVersion(void);
/* Structures to pass information between the option parsing routine
ACT_NOTHING = 0,
ACT_SINGLE_SLASH,
ACT_LIST_DB,
- ACT_SHOW_VER,
ACT_SINGLE_QUERY,
ACT_FILE
};
memset(&settings, 0, sizeof settings);
+ if (!strrchr(argv[0], SEP_CHAR))
+ settings.progname = argv[0];
+ else
+ settings.progname = strrchr(argv[0], SEP_CHAR) + 1;
+
settings.cur_cmd_source = stdin;
settings.cur_cmd_interactive = false;
parse_options(argc, argv, &settings, &options);
- if (options.action == ACT_LIST_DB || options.action == ACT_SHOW_VER)
+ if (options.action == ACT_LIST_DB)
options.dbname = "template1";
if (options.username)
free(username);
free(password);
- if (PQstatus(settings.db) == CONNECTION_BAD && options.action != ACT_SHOW_VER)
+ if (PQstatus(settings.db) == CONNECTION_BAD)
{
- fprintf(stderr, "Connection to database '%s' failed.\n%s\n", PQdb(settings.db), PQerrorMessage(settings.db));
+ fprintf(stderr, "%s: connection to database '%s' failed - %s",
+ settings.progname, PQdb(settings.db), PQerrorMessage(settings.db));
PQfinish(settings.db);
exit(EXIT_BADCONN);
}
exit(!success);
}
- if (options.action == ACT_SHOW_VER)
- {
- showVersion(&settings);
- PQfinish(settings.db);
- exit(EXIT_SUCCESS);
- }
-
if (!GetVariable(settings.vars, "quiet") && !settings.notty && !options.action)
{
- puts("Welcome to psql, the PostgreSQL interactive terminal.\n\n"
- "Type: \\copyright for distribution terms\n"
- " \\h for help with SQL commands\n"
- " \\? for help on internal slash commands\n"
- " \\g or terminate with semicolon to execute query\n"
- " \\q to quit\n");
+ printf("Welcome to %s, the PostgreSQL interactive terminal.\n\n"
+ "Type: \\copyright for distribution terms\n"
+ " \\h for help with SQL commands\n"
+ " \\? for help on internal slash commands\n"
+ " \\g or terminate with semicolon to execute query\n"
+ " \\q to quit\n", settings.progname);
}
process_psqlrc(&settings);
{"echo-all", no_argument, NULL, 'E'},
{"echo-all-queries", no_argument, NULL, 'E'},
{"file", required_argument, NULL, 'f'},
- {"field-sep", required_argument, NULL, 'F'},
+ {"field-separator", required_argument, NULL, 'F'},
{"host", required_argument, NULL, 'h'},
{"html", no_argument, NULL, 'H'},
{"list", no_argument, NULL, 'l'},
{"no-readline", no_argument, NULL, 'n'},
- {"out", required_argument, NULL, 'o'},
- {"to-file", required_argument, NULL, 'o'},
+ {"output", required_argument, NULL, 'o'},
{"port", required_argument, NULL, 'p'},
{"pset", required_argument, NULL, 'P'},
{"quiet", no_argument, NULL, 'q'},
{
if (!DeleteVariable(pset->vars, value))
{
- fprintf(stderr, "Couldn't delete variable %s.\n", value);
+ fprintf(stderr, "%s: could not delete variable %s\n",
+ pset->progname, value);
exit(EXIT_FAILURE);
}
}
*equal_loc = '\0';
if (!SetVariable(pset->vars, value, equal_loc + 1))
{
- fprintf(stderr, "Couldn't set variable %s to %s.\n", value, equal_loc);
+ fprintf(stderr, "%s: Couldn't set variable %s to %s\n",
+ pset->progname, value, equal_loc);
exit(EXIT_FAILURE);
}
}
break;
}
case 'V':
- options->action = ACT_SHOW_VER;
- break;
+ showVersion();
+ exit(EXIT_SUCCESS);
case 'W':
pset->getPassword = true;
break;
break;
#ifndef HAVE_GETOPT_LONG
case '-':
- fprintf(stderr, "This version of psql was compiled without support for long options.\n"
- "Use -? for help on invocation options.\n");
+ fprintf(stderr, "%s was compiled without support for long options.\n"
+ "Use -? for help on invocation options.\n", pset->progname);
exit(EXIT_FAILURE);
break;
#endif
else if (!options->username)
options->username = argv[optind];
else
- fprintf(stderr, "Warning: extra option %s ignored.\n", argv[optind]);
+ fprintf(stderr, "%s: warning: extra option %s ignored\n",
+ pset->progname, argv[optind]);
optind++;
}
/* showVersion
*
- * Displays the database backend version.
- * Also checks against the version psql was compiled for and makes
- * sure that there are no problems.
- *
- * Returns false if there was a problem retrieving the information
- * or a mismatch was detected.
+ * This output format is intended to match GNU standards.
*/
static void
-showVersion(PsqlSettings *pset)
+showVersion(void)
{
- PGresult *res = NULL;
- const char *versionstr = NULL;
- long int release = 0,
- version = 0,
- subversion = 0;
-
- /* get backend version */
- if (pset->db && PQstatus(pset->db) == CONNECTION_OK) {
- res = PSQLexec(pset, "SELECT version()");
- if (PQresultStatus(res) == PGRES_TUPLES_OK)
- versionstr = PQgetvalue(res, 0, 0);
- }
-
- if (versionstr && strncmp(versionstr, "PostgreSQL ", 11) == 0)
- {
- char *tmp;
-
- release = strtol(&versionstr[11], &tmp, 10);
- version = strtol(tmp + 1, &tmp, 10);
- subversion = strtol(tmp + 1, &tmp, 10);
- }
+ puts("psql (PostgreSQL) " PG_RELEASE "." PG_VERSION "." PG_SUBVERSION);
- printf("Server: %s\npsql", versionstr ? versionstr : "(could not connect)");
+#if defined(USE_READLINE) || defined (USE_HISTORY) || defined(MULTIBYTE)
+ fputs("contains ", stdout);
- if (!versionstr || strcmp(versionstr, PG_VERSION_STR) != 0)
- printf(&PG_VERSION_STR[strcspn(PG_VERSION_STR, " ")]);
- printf(" (" __DATE__ " " __TIME__ ")");
-
-#ifdef MULTIBYTE
- printf(", multibyte");
-#endif
-#ifdef HAVE_GETOPT_LONG
- printf(", long options");
-#endif
#ifdef USE_READLINE
- printf(", readline");
+ fputs("readline", stdout);
+#define _Feature
#endif
+
#ifdef USE_HISTORY
- printf(", history");
+#ifdef _Feature
+ fputs(", ", stdout);
+#else
+#define _Feature
#endif
-#ifdef USE_LOCALE
- printf(", locale");
+ fputs("history", stdout);
#endif
-#ifdef PSQL_ALWAYS_GET_PASSWORDS
- printf(", always password");
+
+#ifdef MULTIBYTE
+#ifdef _Feature
+ fputs(", ", stdout);
+#else
+#define _Feature
#endif
-#ifdef USE_ASSERT_CHECKING
- printf(", assert checks");
+ fputs("multibyte");
#endif
+
+#undef _Feature
- puts("");
-
- if (versionstr && (release < 6 || (release == 6 && version < 5)))
- puts("\nWarning: The server you are connected to is potentially too old for this client\n"
- "version. You should ideally be using clients and servers from the same\n"
- "distribution.");
+ puts(" support");
+#endif
- if (res)
- PQclear(res);
+ puts("Copyright (C) 2000 PostgreSQL Global Development Team");
+ puts("Copyright (C) 1996 Regents of the University of California");
+ puts("Read the file COPYING or use the command \\copyright to see the");
+ puts("usage and distribution terms.");
}
rl_readline_name = "psql";
rl_attempted_completion_function = psql_completion;
- rl_filename_quoting_function = quote_file_name;
- /*rl_filename_dequoting_function = dequote_file_name;*/
- rl_filename_quote_characters = "qwertyuioplkjhgfdsazxcvbnm";
-
rl_special_prefixes = "()'";
rl_basic_word_break_characters = "\t\n\"'`@$><=;|&{ ";
- completion_max_records = rl_completion_query_items + 1;
+ completion_max_records = 100;
+ /* There is a variable rl_completion_query_items for this but apparently
+ it's not defined everywhere. */
database_connection = conn;
}
(void)end; /* not used */
- rl_completion_append_character = ' ';
-
/* Clear a few things. */
completion_charp = NULL;
completion_charpp = NULL;
result = PQexec(*database_connection, query);
if (result != NULL && PQresultStatus(result) != PGRES_TUPLES_OK) {
+#ifdef NOT_USED
fprintf(stderr, "\nThe completion query \"%s\" failed thus: %s\n",
query, PQresStatus(PQresultStatus(result)));
+#endif
PQclear(result);
result = NULL;
}
}
+
+#ifdef NOT_USED
+
/* Surround a string with single quotes. This works for both SQL and
psql internal. Doesn't work so well yet.
*/
}
-#ifdef NOT_USED
+
static char * dequote_file_name(char *text, char quote_char)
{
char *s;
return s;
}
-#endif
+
+#endif /* NOT_USED */
#endif /* USE_READLINE */
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.5 2000/01/12 13:08:55 ishii Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.6 2000/01/12 19:36:36 petere Exp $
#
#-------------------------------------------------------------------------
case "$1" in
--help|-\?)
usage=t
+ break
;;
# options passed on to psql
--host|-h)
MB=`echo $1 | sed 's/^--encoding=//'`
;;
-*)
- echo "$CMDNAME: Unrecognized option: $1. Try -? for help."
+ echo "$CMDNAME: unrecognized option: $1"
+ echo "Try -? for help."
exit 1
;;
*)
done
if [ "$usage" ]; then
- echo ""
echo "Usage: $CMDNAME [options] dbname [description]"
echo ""
- echo " -h HOSTNAME, --host=HOSTNAME "
- echo " -p PORT, --port=PORT "
- echo " -U USERNAME, --username=USERNAME "
- echo " -W, --password "
- echo " -e, --echo "
- echo " -q, --quiet "
- echo " -D PATH, --location=PATH "
- echo " -E ENCODING --encoding=ENCODING "
- echo " -?, --help "
- echo ""
- exit 1
+ echo " -D, --location=PATH Alternative place to store the database"
+ echo " -E, --encoding=ENCODING Multibyte encoding for the database"
+ echo " -h, --host=HOSTNAME Database server host"
+ echo " -p, --port=PORT Database server port"
+ echo " -U, --username=USERNAME Username to connect as"
+ echo " -W, --password Prompt for password"
+#??? echo " -e, --echo "
+ echo " -q, --quiet Don't write any messages"
+ exit 0
fi
mbcode=`pg_encoding "$MB"`
if [ -z "$mbcode" ]
then
- echo "$CMDNAME: \"$MB\" is not a valid encoding name."
+ echo "$CMDNAME: \"$MB\" is not a valid encoding name"
exit 1
fi
fi
if [ -z "$dbname" ]; then
- echo "$CMDNAME: Missing required argument database name. Try -? for help."
+ echo "$CMDNAME: missing required argument database name"
+ echo "Try -? for help."
exit 1
fi
+# escape the quotes
dbpath=`echo $dbpath | sed "s/'/\\\\\'/g"`
dbname=`echo $dbname | sed 's/\"/\\\"/g'`
psql $PSQLOPT -d template1 -c "CREATE DATABASE \"$dbname\"$withstring"
if [ $? -ne 0 ]; then
- echo "$CMDNAME: Database creation failed."
+ echo "$CMDNAME: database creation failed"
exit 1
fi
psql $PSQLOPT -d template1 -c "COMMENT ON DATABASE \"$dbname\" IS '$dbcomment'"
if [ $? -ne 0 ]; then
- echo "$CMDNAME: Comment creation failed. (Database was created.)"
+ echo "$CMDNAME: comment creation failed (database was created)"
exit 1
fi
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.4 1999/12/17 18:05:32 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.5 2000/01/12 19:36:36 petere Exp $
#
#-------------------------------------------------------------------------
fi
-# ----------
-# Find the default PGLIB directory
-# ----------
-postconfig_result="`sh -c postconfig 2>/dev/null`"
-if [ "$postconfig_result" ]; then
- set -a
- eval "$postconfig_result"
- set +a
-fi
-
# ----------
# Get options, language name and dbname
case "$1" in
--help|-\?)
usage=t
+ break
;;
--list|-l)
list=t
PGLIB=`echo $1 | sed 's/^--pglib=//'`
;;
+ -*)
+ echo "$CMDNAME: unrecognized option: $1"
+ echo "Try -? for help."
+ exit 1
+ ;;
*)
langname="$1"
if [ "$2" ]; then
echo ""
echo "Usage: $CMDNAME [options] [langname [dbname]]"
echo ""
- echo " -h HOSTNAME, --host=HOSTNAME "
- echo " -p PORT, --port=PORT "
- echo " -U USERNAME, --username=USERNAME "
- echo " -l, --list "
- echo " -W, --password "
- echo " -d DBNAME, --database=DBNAME "
- echo " -e, --echo "
- echo " -D PATH, --location=PATH "
- echo " -L PGLIB --pglib=PGLIB "
- echo " -?, --help "
- echo ""
- exit 1
+ echo " -h, --host=HOSTNAME Database server host"
+ echo " -p, --port=PORT Database server port"
+ echo " -U, --username=USERNAME Username to connect as"
+ echo " -W, --password Prompt for password"
+ echo " -d, --dbname=DBNAME Database to install language in"
+ echo " -e, --echo Create some output about what is happening"
+ echo " -L, --pglib=PGLIB Find language interpreter in directory PGLIB"
+ echo " -l, --list Show a list of currently installed languages"
+ exit 0
fi
if [ "$list" ]; then
# Check that we have a database
# ----------
if [ -z "$dbname" ]; then
- echo "$CMDNAME: Missing required argument database name. Try -? for help."
+ echo "$CMDNAME: missing required argument database name"
+ echo "Try -? for help."
exit 1
fi
# Check that we have PGLIB
# ----------
if [ -z "$PGLIB" ]; then
- echo "Cannot determine the PostgreSQL lib directory (PGLIB). You must"
- echo "identify it either with a --pglib option or by setting the PGLIB"
- echo "environment variable."
+ echo "$CMDNAME: missing required argument PGLIB directory"
+ echo "(This is the directory where the interpreter for the procedural"
+ echo "language is stored. Traditionally, these are installed in whatever"
+ echo "'lib' directory was specified at configure time.)"
exit 1
fi
trusted="TRUSTED "
handler="pltcl_call_handler";;
*)
- echo "$CMDNAME: Unsupported language '$langname'."
+ echo "$CMDNAME: unsupported language '$langname'"
echo "Supported languages are 'plpgsql' and 'pltcl'."
exit 1
;;
# in PGLIB
# ----------
if [ ! -f $PGLIB/${langname}__DLSUFFIX__ ]; then
- echo "Cannot find the file $PGLIB/${langname}__DLSUFFIX__."
+ echo "$CMDNAME: cannot find the file $PGLIB/${langname}__DLSUFFIX__"
echo ""
echo "This file contains the call handler for $lancomp. By default,"
echo "only PL/pgSQL is built and installed; other languages must be"
# ----------
res=`$PSQL "SELECT oid FROM pg_language WHERE lanname = '$langname'"`
if [ $? -ne 0 ]; then
- echo "Language installation failed."
+ echo "$CMDNAME: external error"
exit 1
fi
if [ "$res" ]; then
- echo "The language '$langname' is already installed in database $dbname."
- exit 2
+ echo "$CMDNAME: '$langname' is already installed in database $dbname"
+ exit 1
fi
# ----------
# ----------
res=`$PSQL "SELECT oid FROM pg_proc WHERE proname = '$handler'"`
if [ ! -z "$res" ]; then
- echo "The language $lancomp isn't created up to now but there is"
- echo "already a function named '$handler' declared."
- echo "Language installation aborted."
+ echo "$CMDNAME: A function named '$handler' already exists. Installation aborted."
exit 1
fi
# ----------
$PSQL "CREATE FUNCTION $handler () RETURNS OPAQUE AS '$PGLIB/${langname}__DLSUFFIX__' LANGUAGE 'C'"
if [ $? -ne 0 ]; then
- echo "Language installation failed."
+ echo "$CMDNAME: language installation failed"
exit 1
fi
$PSQL "CREATE ${trusted}PROCEDURAL LANGUAGE '$langname' HANDLER $handler LANCOMPILER '$lancomp'"
if [ $? -ne 0 ]; then
- echo "Language installation failed."
+ echo "$CMDNAME: language installation failed"
exit 1
fi
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.4 1999/12/16 20:10:02 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.5 2000/01/12 19:36:36 petere Exp $
#
# Note - this should NOT be setuid.
#
case "$1" in
--help|-\?)
usage=t
+ break
;;
# options passed on to psql
--host|-h)
PwPrompt=t
;;
-*)
- echo "$CMDNAME: Unrecognized option: $1. Try -? for help."
+ echo "$CMDNAME: unrecognized option: $1"
+ echo "Try -? for help."
exit 1
;;
*)
done
if [ "$usage" ]; then
- echo ""
echo "Usage: $CMDNAME [options] [username]"
echo ""
- echo " -h HOSTNAME, --host=HOSTNAME "
- echo " -p PORT, --port=PORT "
- echo " -d, --createdb "
- echo " -D, --no-createdb "
- echo " -a, --adduser "
- echo " -A, --no-adduser "
- echo " -i SYSID, --sysid=SYSID "
- echo " -P, --pwprompt "
- echo " -U USERNAME, --username=USERNAME (for connect to db)"
- echo " -W, --password (for connect to db)"
- echo " -e, --echo "
- echo " -q, --quiet "
- echo " -?, --help "
- echo ""
- exit 1
+ echo " -d, --createdb User can create new databases"
+ echo " -D, --no-createdb User cannot create databases"
+ echo " -a, --adduser User can add new users"
+ echo " -A, --no-adduser User cannot add new users"
+ echo " -i, --sysid=SYSID Select sysid for new user"
+ echo " -P, --pwprompt Assign a password to new user"
+ echo " -h, --host=HOSTNAME Database server host"
+ echo " -p, --port=PORT Database server port"
+ echo " -U, --username=USERNAME Username to connect as (not the one to create)"
+ echo " -W, --password Prompt for password to connect"
+#??? echo " -e, --echo "
+ echo " -q, --quiet Don't write any messages"
+ exit 0
fi
if [ "$SysID" ]; then
if [ "$SysID" != "`echo $SysID | sed 's/[^0-9]//g'`" ]; then
- echo "$CMDNAME: User sysid must be a positive number."
+ echo "$CMDNAME: user sysid must be a positive number"
exit 1
fi
fi
psql $PSQLOPT -d template1 -c "$QUERY"
if [ $? -ne 0 ]; then
- echo "$CMDNAME: Creation of user \"$NewUser\" failed."
+ echo "$CMDNAME: creation of user \"$NewUser\" failed"
exit 1
fi
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.4 1999/12/16 20:10:02 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.5 2000/01/12 19:36:36 petere Exp $
#
#-------------------------------------------------------------------------
if [ "$usage" ]; then
- echo ""
echo "Usage: $CMDNAME [options] dbname"
echo ""
- echo " -h HOSTNAME, --host=HOSTNAME "
- echo " -p PORT, --port=PORT "
- echo " -u USERNAME, --username=USERNAME "
- echo " -W, --password "
- echo " -e, --echo "
- echo " -q, --quiet "
- echo " -i, --interactive "
- echo " -?, --help "
- echo ""
- exit 1
+ echo " -h, --host=HOSTNAME Database server host"
+ echo " -p, --port=PORT Database server port"
+ echo " -U, --username=USERNAME Username to connect as"
+ echo " -W, --password Prompt for password"
+ echo " -i, --interactive Prompt before deleting anything"
+#??? echo " -e, --echo "
+ echo " -q, --quiet Don't write any messages"
+ exit 0
fi
if [ -z "$dbname" ]; then
- echo "$CMDNAME: Missing required argument database name. Try -? for help."
+ echo "$CMDNAME: missing required argument database name"
+ echo "Try -? for help."
exit 1
fi
psql $PSQLOPT -d template1 -c "DROP DATABASE \"$dbname\""
if [ $? -ne 0 ]; then
- echo "$CMDNAME: Database removal failed."
+ echo "$CMDNAME: database removal failed"
exit 1
fi
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.4 1999/12/16 20:10:02 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.5 2000/01/12 19:36:36 petere Exp $
#
#-------------------------------------------------------------------------
case "$1" in
--help|-\?)
usage=t
+ break
;;
--list|-l)
list=t
dbname=`echo $1 | sed 's/^--database=//'`
;;
+ -*)
+ echo "$CMDNAME: unrecognized option: $1"
+ echo "Try -? for help."
+ exit 1
+ ;;
*)
langname="$1"
if [ "$2" ]; then
if [ "$usage" ]; then
echo ""
- echo "Usage: $CMDNAME [options] [language [dbname]]"
+ echo "Usage: $CMDNAME [options] [langname [dbname]]"
echo ""
- echo " -h HOSTNAME, --host=HOSTNAME "
- echo " -p PORT, --port=PORT "
- echo " -u USERNAME, --username=USERNAME "
- echo " -W, --password "
- echo " -d DBNAME --database=DBNAME "
- echo " -e, --echo "
- echo " -q, --quiet "
- echo " -?, --help "
- echo ""
- exit 1
+ echo " -h, --host=HOSTNAME Database server host"
+ echo " -p, --port=PORT Database server port"
+ echo " -U, --username=USERNAME Username to connect as"
+ echo " -W, --password Prompt for password"
+ echo " -d, --dbname=DBNAME Database to remove language from"
+ echo " -e, --echo Create some output about what is happening"
+ echo " -l, --list Show a list of currently installed languages"
+ exit 0
fi
# Check that we have a database
# ----------
if [ -z "$dbname" ]; then
- echo "$CMDNAME: Missing required argument database name. Try -? for help."
+ echo "$CMDNAME: missing required argument database name"
+ echo "Try -? for help."
exit 1
fi
handler="pltcl_call_handler"
;;
*)
- echo "$CMDNAME: Unsupported language '$langname'."
- echo " Supported languages are 'plpgsql' and 'pltcl'."
+ echo "$CMDNAME: unsupported language '$langname'"
+ echo "Supported languages are 'plpgsql' and 'pltcl'."
exit 1
;;
esac
# ----------
res=`$PSQL "SELECT oid FROM pg_language WHERE lanname = '$langname'"`
if [ $? -ne 0 ]; then
- echo "Language removal failed."
+ echo "$CMDNAME: external error"
exit 1
fi
if [ -z "$res" ]; then
- echo "The language '$langname' isn't installed in database $dbname."
+ echo "$CMDNAME: '$langname' is not installed in database $dbname"
exit 1
fi
# ----------
res=`$PSQL "SELECT COUNT(proname) FROM pg_proc P, pg_language L WHERE P.prolang = L.oid AND L.lanname = '$langname'"`
if [ $? -ne 0 ]; then
- echo "Language removal failed."
+ echo "$CMDNAME: external error"
exit 1
fi
if [ $res -ne 0 ]; then
- echo "There are $res functions/trigger procedures declared in language"
- echo "$lancomp."
- echo "Language not removed."
+ echo "$CMDNAME: There are $res functions/trigger procedures declared in language"
+ echo "$lancomp. Language not removed."
exit 1
fi
# ----------
$PSQL "DROP PROCEDURAL LANGUAGE '$langname'"
if [ $? -ne 0 ]; then
- echo "Language removal failed."
+ echo "$CMDNAME: language removal failed"
exit 1
fi
$PSQL "DROP FUNCTION $handler()"
if [ $? -ne 0 ]; then
- echo "Language removal failed."
+ echo "$CMDNAME: language removal failed"
exit 1
fi
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.4 1999/12/16 20:10:02 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.5 2000/01/12 19:36:36 petere Exp $
#
# Note - this should NOT be setuid.
#
case "$1" in
--help|-\?)
usage=t
+ break
;;
# options passed on to psql
--host|-h)
echo ""
echo "Usage: $CMDNAME [options] [username]"
echo ""
- echo " -h HOSTNAME, --host=HOSTNAME "
- echo " -p PORT, --port=PORT "
- echo " -u USERNAME, --username=USERNAME (for connect to db)"
- echo " -W, --password "
- echo " -e, --echo "
- echo " -q, --quiet "
- echo " -i, --interactive "
- echo " -?, --help "
- echo ""
- exit 1
+ echo " -h, --host=HOSTNAME Database server host"
+ echo " -p, --port=PORT Database server port"
+ echo " -U, --username=USERNAME Username to connect as (not the one to drop)"
+ echo " -W, --password Prompt for password to connect"
+ echo " -i, --interactive Prompt before deleting anything"
+#??? echo " -e, --echo "
+ echo " -q, --quiet Don't write any messages"
+ exit 0
fi
# Prompt for username if missing
psql $PSQLOPT -d template1 -c "DROP USER \"$DelUser\""
if [ $? -ne 0 ]; then
- echo "$CMDNAME: Deletion of user \"$DelUser\" failed."
+ echo "$CMDNAME: deletion of user \"$DelUser\" failed"
exit 1
fi
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.7 1999/12/18 08:46:44 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.8 2000/01/12 19:36:36 petere Exp $
#
#-------------------------------------------------------------------------
case "$1" in
--help|-\?)
usage=t
+ break
;;
# options passed on to psql
--host|-h)
--analyze|-z)
analyze="ANALYZE "
;;
- --alldb|-a)
+ --all|-a)
alldb=Y
;;
--table|-t)
;;
-*)
- echo "$CMDNAME: Unrecognized option: $1. Try -? for help."
+ echo "$CMDNAME: unrecognized option: $1"
+ echo "Try -? for help."
exit 1
;;
*)
done
if [ "$usage" ]; then
- echo ""
echo "Usage: $CMDNAME [options] [dbname]"
echo ""
- echo " -h HOSTNAME, --host=HOSTNAME "
- echo " -p PORT, --port=PORT "
- echo " -u USERNAME, --username=USERNAME "
- echo " -W, --password "
- echo " -d DBNAME, --database=DBNAME "
- echo " -z, --analyze "
- echo " -a, --alldb "
- echo " -t TABLE[(columns)], --table=TABLE[(columns)]"
- echo " -v, --verbose "
- echo " -e, --echo "
- echo " -q, --quiet "
- echo " -?, --help "
- echo ""
- exit 1
+ echo " -h, --host=HOSTNAME Database server host"
+ echo " -p, --port=PORT Database server port"
+ echo " -U, --username=USERNAME Username to connect as"
+ echo " -W, --password Prompt for password"
+ echo " -d, --dbname=DBNAME Database to vacuum"
+ echo " -a, --all Vacuum all databases"
+ echo " -z, --analyze Update optimizer hints"
+ echo " -t, --table='TABLE[(columns)]' Vacuum specific table only"
+ echo " -v, --verbose Write a lot of output"
+#??? echo " -e, --echo "
+ echo " -q, --quiet Don't write any output"
+ exit 0
fi
-if [ ! -z "$alldb" ]; then
- dbname="`psql $PASSWDOPT $AUTHOPT $PGHOSTOPT $PGPORTOPT -q -t -A -d template1 -c 'SELECT datname FROM pg_database'`"
+if [ "$alldb" ]; then
+ if [ "$dbname" -o "$table" ]; then
+ echo "$CMDNAME: cannot vacuum all databases and a specific one at the same time"
+ exit 1
+ fi
+ dbname="`psql $PSQLOPT -q -t -A -d template1 -c 'SELECT datname FROM pg_database'`"
fi
if [ -z "$dbname" ]; then
- echo "$CMDNAME: Missing required argument database name. Try -? for help."
+ echo "$CMDNAME: missing required argument database name"
+ echo "Try -? for help."
exit 1
fi
for db in $dbname
do
- psql $PASSWDOPT -tq $AUTHOPT $PGHOSTOPT $PGPORTOPT -c "vacuum $verbose $analyze $table" $db
+ psql $PSQLOPT -c "vacuum $verbose $analyze $table" -d $dbname
done
-if [ $? -ne 0 ]
-then
- echo "$CMDNAME: Vacuum failed."
+if [ $? -ne 0 ]; then
+ echo "$CMDNAME: vacuum failed"
exit 1
fi