2000-01-19 00:30:24 +01:00
/*
* psql - the PostgreSQL interactive terminal
*
2007-01-05 23:20:05 +01:00
* Copyright ( c ) 2000 - 2007 , PostgreSQL Global Development Group
2000-01-19 00:30:24 +01:00
*
2007-04-27 00:25:56 +02:00
* $ PostgreSQL : pgsql / src / bin / psql / tab - complete . c , v 1.164 2007 / 04 / 26 22 : 25 : 56 neilc Exp $
2000-01-19 00:30:24 +01:00
*/
2000-06-25 16:25:51 +02:00
/*----------------------------------------------------------------------
* This file implements a somewhat more sophisticated readline " TAB
* completion " in psql. It is not intended to be AI, to replace
* learning SQL , or to relieve you from thinking about what you ' re
* doing . Also it does not always give you all the syntactically legal
* completions , only those that are the most common or the ones that
* the programmer felt most like implementing .
*
* CAVEAT : Tab completion causes queries to be sent to the backend .
2003-10-16 22:03:09 +02:00
* The number of tuples returned gets limited , in most default
* installations to 1000 , but if you still don ' t like this prospect ,
2000-06-25 16:25:51 +02:00
* you can turn off tab completion in your ~ / . inputrc ( or else
* $ { INPUTRC } ) file so :
*
2001-03-22 05:01:46 +01:00
* $ if psql
* set disable - completion on
* $ endif
2000-06-25 16:25:51 +02:00
*
* See ` man 3 readline ' or ` info readline ' for the full details . Also ,
* hence the
*
* BUGS :
*
2003-10-16 22:03:09 +02:00
* - If you split your queries across lines , this whole thing gets
2001-03-22 05:01:46 +01:00
* confused . ( To fix this , one would have to read psql ' s query
* buffer rather than readline ' s line buffer , which would require
* some major revisions of things . )
2000-06-25 16:25:51 +02:00
*
2002-07-30 18:35:05 +02:00
* - Table or attribute names with spaces in it may confuse it .
2000-06-25 16:25:51 +02:00
*
* - Quotes , parenthesis , and other funny characters are not handled
2001-03-22 05:01:46 +01:00
* all that gracefully .
2000-06-25 16:25:51 +02:00
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2001-02-10 03:31:31 +01:00
# include "postgres_fe.h"
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
# include "tab-complete.h"
# include "input.h"
/* If we don't have this, we might as well forget about the whole thing: */
# ifdef USE_READLINE
2000-12-03 21:45:40 +01:00
# include <ctype.h>
2000-02-16 14:15:26 +01:00
# include "libpq-fe.h"
2006-06-12 01:06:00 +02:00
# include "pqexpbuffer.h"
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
# include "common.h"
2000-01-19 00:30:24 +01:00
# include "settings.h"
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2001-06-12 00:12:48 +02:00
# ifdef HAVE_RL_FILENAME_COMPLETION_FUNCTION
# define filename_completion_function rl_filename_completion_function
2001-06-20 20:39:14 +02:00
# else
/* missing in some header files */
extern char * filename_completion_function ( ) ;
2001-06-12 00:12:48 +02:00
# endif
2000-04-12 19:17:23 +02:00
2001-04-15 00:55:02 +02:00
# ifdef HAVE_RL_COMPLETION_MATCHES
2003-04-03 22:18:16 +02:00
# define completion_matches rl_completion_matches
2000-03-05 14:30:20 +01:00
# endif
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2003-10-30 22:37:38 +01:00
/*
* This struct is used to define " schema queries " , which are custom - built
* to obtain possibly - schema - qualified names of database objects . There is
* enough similarity in the structure that we don ' t want to repeat it each
* time . So we put the components of each query into this struct and
* assemble them with the common boilerplate in _complete_from_query ( ) .
*/
typedef struct SchemaQuery
{
/*
* Name of catalog or catalogs to be queried , with alias , eg .
* " pg_catalog.pg_class c " . Note that " pg_namespace n " will be added .
*/
const char * catname ;
2004-08-29 07:07:03 +02:00
2003-10-30 22:37:38 +01:00
/*
2005-10-15 04:49:52 +02:00
* Selection condition - - - only rows meeting this condition are candidates
* to display . If catname mentions multiple tables , include the necessary
* join condition here . For example , " c.relkind = 'r' " . Write NULL ( not
* an empty string ) if not needed .
2003-10-30 22:37:38 +01:00
*/
const char * selcondition ;
2004-08-29 07:07:03 +02:00
2003-10-30 22:37:38 +01:00
/*
* Visibility condition - - - which rows are visible without schema
2005-10-15 04:49:52 +02:00
* qualification ? For example , " pg_catalog.pg_table_is_visible(c.oid) " .
2003-10-30 22:37:38 +01:00
*/
const char * viscondition ;
2004-08-29 07:07:03 +02:00
2003-10-30 22:37:38 +01:00
/*
2005-10-15 04:49:52 +02:00
* Namespace - - - name of field to join to pg_namespace . oid . For example ,
* " c.relnamespace " .
2003-10-30 22:37:38 +01:00
*/
const char * namespace ;
2004-08-29 07:07:03 +02:00
2003-10-30 22:37:38 +01:00
/*
2005-10-15 04:49:52 +02:00
* Result - - - the appropriately - quoted name to return , in the case of an
* unqualified name . For example , " pg_catalog.quote_ident(c.relname) " .
2003-10-30 22:37:38 +01:00
*/
const char * result ;
2004-08-29 07:07:03 +02:00
2003-10-30 22:37:38 +01:00
/*
* In some cases a different result must be used for qualified names .
* Enter that here , or write NULL if result can be used .
*/
const char * qualresult ;
} SchemaQuery ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2000-04-12 19:17:23 +02:00
2003-10-30 22:37:38 +01:00
/* Store maximum number of records we want from database queries
* ( implemented via SELECT . . . LIMIT xx ) .
*/
static int completion_max_records ;
2000-04-12 19:17:23 +02:00
2003-10-30 22:37:38 +01:00
/*
* Communication variables set by COMPLETE_WITH_FOO macros and then used by
* the completion callback functions . Ugly but there is no better way .
*/
static const char * completion_charp ; /* to pass a string */
2005-10-15 04:49:52 +02:00
static const char * const * completion_charpp ; /* to pass a list of strings */
2004-08-29 07:07:03 +02:00
static const char * completion_info_charp ; /* to pass a second string */
static const SchemaQuery * completion_squery ; /* to pass a SchemaQuery */
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2003-10-30 22:37:38 +01:00
/* A couple of macros to ease typing. You can use these to complete the given
string with
1 ) The results from a query you pass it . ( Perhaps one of those below ? )
2 ) The results from a schema query you pass it .
3 ) The items from a null - pointer - terminated list .
4 ) A string constant
5 ) The list of attributes to the given table .
*/
# define COMPLETE_WITH_QUERY(query) \
do { completion_charp = query ; matches = completion_matches ( text , complete_from_query ) ; } while ( 0 )
2006-02-12 08:21:40 +01:00
# define COMPLETE_WITH_SCHEMA_QUERY(query, addon) \
2003-10-30 22:37:38 +01:00
do { completion_squery = & ( query ) ; completion_charp = addon ; matches = completion_matches ( text , complete_from_schema_query ) ; } while ( 0 )
# define COMPLETE_WITH_LIST(list) \
do { completion_charpp = list ; matches = completion_matches ( text , complete_from_list ) ; } while ( 0 )
# define COMPLETE_WITH_CONST(string) \
do { completion_charp = string ; matches = completion_matches ( text , complete_from_const ) ; } while ( 0 )
2006-02-12 08:21:40 +01:00
# define COMPLETE_WITH_ATTR(table, addon) \
do { completion_charp = Query_for_list_of_attributes addon ; completion_info_charp = table ; matches = completion_matches ( text , complete_from_query ) ; } while ( 0 )
2003-10-15 00:47:12 +02:00
2003-10-30 22:37:38 +01:00
/*
* Assembly instructions for schema queries
*/
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2003-10-30 22:37:38 +01:00
static const SchemaQuery Query_for_list_of_aggregates = {
/* catname */
" pg_catalog.pg_proc p " ,
/* selcondition */
" p.proisagg " ,
/* viscondition */
" pg_catalog.pg_function_is_visible(p.oid) " ,
/* namespace */
" p.pronamespace " ,
/* result */
" pg_catalog.quote_ident(p.proname) " ,
/* qualresult */
NULL
} ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2003-10-30 22:37:38 +01:00
static const SchemaQuery Query_for_list_of_datatypes = {
/* catname */
" pg_catalog.pg_type t " ,
/* selcondition --- ignore table rowtypes and array types */
" (t.typrelid = 0 "
" OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid)) "
" AND t.typname !~ '^_' " ,
/* viscondition */
" pg_catalog.pg_type_is_visible(t.oid) " ,
/* namespace */
" t.typnamespace " ,
/* result */
" pg_catalog.format_type(t.oid, NULL) " ,
/* qualresult */
" pg_catalog.quote_ident(t.typname) "
} ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2003-10-30 22:37:38 +01:00
static const SchemaQuery Query_for_list_of_domains = {
/* catname */
" pg_catalog.pg_type t " ,
/* selcondition */
" t.typtype = 'd' " ,
/* viscondition */
" pg_catalog.pg_type_is_visible(t.oid) " ,
/* namespace */
" t.typnamespace " ,
/* result */
" pg_catalog.quote_ident(t.typname) " ,
/* qualresult */
NULL
} ;
2000-04-12 19:17:23 +02:00
2003-10-30 22:37:38 +01:00
static const SchemaQuery Query_for_list_of_functions = {
/* catname */
" pg_catalog.pg_proc p " ,
/* selcondition */
NULL ,
/* viscondition */
" pg_catalog.pg_function_is_visible(p.oid) " ,
/* namespace */
" p.pronamespace " ,
/* result */
" pg_catalog.quote_ident(p.proname) " ,
/* qualresult */
NULL
} ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2003-10-30 22:37:38 +01:00
static const SchemaQuery Query_for_list_of_indexes = {
/* catname */
" pg_catalog.pg_class c " ,
/* selcondition */
" c.relkind IN ('i') " ,
/* viscondition */
" pg_catalog.pg_table_is_visible(c.oid) " ,
/* namespace */
" c.relnamespace " ,
/* result */
" pg_catalog.quote_ident(c.relname) " ,
/* qualresult */
NULL
} ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2003-10-30 22:37:38 +01:00
static const SchemaQuery Query_for_list_of_sequences = {
/* catname */
" pg_catalog.pg_class c " ,
/* selcondition */
" c.relkind IN ('S') " ,
/* viscondition */
" pg_catalog.pg_table_is_visible(c.oid) " ,
/* namespace */
" c.relnamespace " ,
/* result */
" pg_catalog.quote_ident(c.relname) " ,
/* qualresult */
NULL
} ;
static const SchemaQuery Query_for_list_of_tables = {
/* catname */
" pg_catalog.pg_class c " ,
/* selcondition */
" c.relkind IN ('r') " ,
/* viscondition */
" pg_catalog.pg_table_is_visible(c.oid) " ,
/* namespace */
" c.relnamespace " ,
/* result */
" pg_catalog.quote_ident(c.relname) " ,
/* qualresult */
NULL
} ;
static const SchemaQuery Query_for_list_of_tisv = {
/* catname */
" pg_catalog.pg_class c " ,
/* selcondition */
" c.relkind IN ('r', 'i', 'S', 'v') " ,
/* viscondition */
" pg_catalog.pg_table_is_visible(c.oid) " ,
/* namespace */
" c.relnamespace " ,
/* result */
" pg_catalog.quote_ident(c.relname) " ,
/* qualresult */
NULL
} ;
static const SchemaQuery Query_for_list_of_tsv = {
/* catname */
" pg_catalog.pg_class c " ,
/* selcondition */
" c.relkind IN ('r', 'S', 'v') " ,
/* viscondition */
" pg_catalog.pg_table_is_visible(c.oid) " ,
/* namespace */
" c.relnamespace " ,
/* result */
" pg_catalog.quote_ident(c.relname) " ,
/* qualresult */
NULL
} ;
static const SchemaQuery Query_for_list_of_views = {
/* catname */
" pg_catalog.pg_class c " ,
/* selcondition */
" c.relkind IN ('v') " ,
/* viscondition */
" pg_catalog.pg_table_is_visible(c.oid) " ,
/* namespace */
" c.relnamespace " ,
/* result */
" pg_catalog.quote_ident(c.relname) " ,
/* qualresult */
NULL
} ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2002-08-10 05:56:24 +02:00
/*
* Queries to get lists of names of various kinds of things , possibly
* restricted to names matching a partially entered name . In these queries ,
2003-10-15 00:47:12 +02:00
* % s will be replaced by the text entered so far ( suitably escaped to
* become a SQL literal string ) . % d will be replaced by the length of the
2004-08-29 07:07:03 +02:00
* string ( in unescaped form ) . A second % s , if present , will be replaced
2003-10-30 22:37:38 +01:00
* by a suitably - escaped version of the string provided in
* completion_info_charp .
*
* Beware that the allowed sequences of % s and % d are determined by
* _complete_from_query ( ) .
2002-08-10 05:56:24 +02:00
*/
2003-03-27 17:45:01 +01:00
# define Query_for_list_of_attributes \
2003-10-16 22:03:09 +02:00
" SELECT pg_catalog.quote_ident(attname) " \
" FROM pg_catalog.pg_attribute a, pg_catalog.pg_class c " \
2003-03-27 17:45:01 +01:00
" WHERE c.oid = a.attrelid " \
" AND a.attnum > 0 " \
" AND NOT a.attisdropped " \
2003-10-16 22:03:09 +02:00
" AND substring(pg_catalog.quote_ident(attname),1,%d)='%s' " \
" AND pg_catalog.quote_ident(relname)='%s' " \
2003-03-27 17:45:01 +01:00
" AND pg_catalog.pg_table_is_visible(c.oid) "
# define Query_for_list_of_databases \
2003-10-16 22:03:09 +02:00
" SELECT pg_catalog.quote_ident(datname) FROM pg_catalog.pg_database " \
" WHERE substring(pg_catalog.quote_ident(datname),1,%d)='%s' "
2003-03-27 17:45:01 +01:00
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
# define Query_for_list_of_tablespaces \
" SELECT pg_catalog.quote_ident(spcname) FROM pg_catalog.pg_tablespace " \
" WHERE substring(pg_catalog.quote_ident(spcname),1,%d)='%s' "
2003-06-12 03:38:08 +02:00
# define Query_for_list_of_encodings \
" SELECT DISTINCT pg_catalog.pg_encoding_to_char(conforencoding) " \
" FROM pg_catalog.pg_conversion " \
2003-10-16 22:03:09 +02:00
" WHERE substring(pg_catalog.pg_encoding_to_char(conforencoding),1,%d)=UPPER('%s') "
2003-06-12 03:38:08 +02:00
2003-03-27 17:45:01 +01:00
# define Query_for_list_of_languages \
2003-10-16 22:03:09 +02:00
" SELECT pg_catalog.quote_ident(lanname) " \
2003-03-27 17:45:01 +01:00
" FROM pg_language " \
" WHERE lanname != 'internal' " \
2003-10-16 22:03:09 +02:00
" AND substring(pg_catalog.quote_ident(lanname),1,%d)='%s' "
2003-03-27 17:45:01 +01:00
# define Query_for_list_of_schemas \
2003-10-16 22:03:09 +02:00
" SELECT pg_catalog.quote_ident(nspname) FROM pg_catalog.pg_namespace " \
" WHERE substring(pg_catalog.quote_ident(nspname),1,%d)='%s' "
2003-03-27 17:45:01 +01:00
2005-08-14 20:49:30 +02:00
# define Query_for_list_of_set_vars \
" SELECT name FROM " \
" (SELECT pg_catalog.lower(name) AS name FROM pg_catalog.pg_settings " \
" WHERE context IN ('user', 'superuser') " \
" UNION ALL SELECT 'constraints' " \
" UNION ALL SELECT 'transaction' " \
" UNION ALL SELECT 'session' " \
" UNION ALL SELECT 'role' " \
" UNION ALL SELECT 'all') ss " \
" WHERE substring(name,1,%d)='%s' "
# define Query_for_list_of_show_vars \
" SELECT name FROM " \
" (SELECT pg_catalog.lower(name) AS name FROM pg_catalog.pg_settings " \
" UNION ALL SELECT 'session authorization' " \
" UNION ALL SELECT 'all') ss " \
" WHERE substring(name,1,%d)='%s' "
2006-05-28 04:27:08 +02:00
/*
* Note : As of Pg 8.2 , we no longer use relkind ' s ' , but we keep it here
* for compatibility with older servers
*/
2003-03-27 17:45:01 +01:00
# define Query_for_list_of_system_relations \
2003-10-16 22:03:09 +02:00
" SELECT pg_catalog.quote_ident(relname) " \
" FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n " \
2003-10-30 22:37:38 +01:00
" WHERE c.relkind IN ('r', 'v', 's', 'S') " \
2003-10-16 22:03:09 +02:00
" AND substring(pg_catalog.quote_ident(relname),1,%d)='%s' " \
2003-10-30 22:37:38 +01:00
" AND c.relnamespace = n.oid " \
2003-03-27 17:45:01 +01:00
" AND n.nspname = 'pg_catalog' "
2005-08-14 20:49:30 +02:00
# define Query_for_list_of_roles \
" SELECT pg_catalog.quote_ident(rolname) " \
" FROM pg_catalog.pg_roles " \
" WHERE substring(pg_catalog.quote_ident(rolname),1,%d)='%s' "
2002-08-10 05:56:24 +02:00
2005-08-14 20:49:30 +02:00
# define Query_for_list_of_grant_roles \
" SELECT pg_catalog.quote_ident(rolname) " \
" FROM pg_catalog.pg_roles " \
" WHERE substring(pg_catalog.quote_ident(rolname),1,%d)='%s' " \
" UNION ALL SELECT 'PUBLIC' "
2005-05-18 06:47:40 +02:00
2003-10-15 00:47:12 +02:00
/* the silly-looking length condition is just to eat up the current word */
# define Query_for_table_owning_index \
2003-10-16 22:03:09 +02:00
" SELECT pg_catalog.quote_ident(c1.relname) " \
2003-10-15 00:47:12 +02:00
" FROM pg_catalog.pg_class c1, pg_catalog.pg_class c2, pg_catalog.pg_index i " \
" WHERE c1.oid=i.indrelid and i.indexrelid=c2.oid " \
" and (%d = length('%s')) " \
2003-10-16 22:03:09 +02:00
" and pg_catalog.quote_ident(c2.relname)='%s' " \
2003-10-15 00:47:12 +02:00
" and pg_catalog.pg_table_is_visible(c2.oid) "
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
/* the silly-looking length condition is just to eat up the current word */
# define Query_for_index_of_table \
" SELECT pg_catalog.quote_ident(c2.relname) " \
" FROM pg_catalog.pg_class c1, pg_catalog.pg_class c2, pg_catalog.pg_index i " \
" WHERE c1.oid=i.indrelid and i.indexrelid=c2.oid " \
" and (%d = length('%s')) " \
" and pg_catalog.quote_ident(c1.relname)='%s' " \
" and pg_catalog.pg_table_is_visible(c2.oid) "
2004-09-22 06:25:16 +02:00
/* the silly-looking length condition is just to eat up the current word */
# define Query_for_list_of_tables_for_trigger \
" SELECT pg_catalog.quote_ident(relname) " \
" FROM pg_catalog.pg_class " \
" WHERE (%d = length('%s')) " \
" AND oid IN " \
" (SELECT tgrelid FROM pg_catalog.pg_trigger " \
" WHERE pg_catalog.quote_ident(tgname)='%s') "
2003-10-30 22:37:38 +01:00
/*
* This is a list of all " things " in Pgsql , which can show up after CREATE or
* DROP ; and there is also a query to get a list of them .
*/
2003-03-27 17:45:01 +01:00
2000-04-12 19:17:23 +02:00
typedef struct
{
2003-10-30 22:37:38 +01:00
const char * name ;
const char * query ; /* simple query, or NULL */
const SchemaQuery * squery ; /* schema query, or NULL */
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
} pgsql_thing_t ;
2003-10-30 22:37:38 +01:00
static const pgsql_thing_t words_after_create [ ] = {
{ " AGGREGATE " , NULL , & Query_for_list_of_aggregates } ,
2005-10-15 04:49:52 +02:00
{ " CAST " , NULL , NULL } , /* Casts have complex structures for names, so
* skip it */
/*
* CREATE CONSTRAINT TRIGGER is not supported here because it is designed
* to be used only by pg_dump .
*/
2003-10-30 22:37:38 +01:00
{ " CONVERSION " , " SELECT pg_catalog.quote_ident(conname) FROM pg_catalog.pg_conversion WHERE substring(pg_catalog.quote_ident(conname),1,%d)='%s' " } ,
{ " DATABASE " , Query_for_list_of_databases } ,
{ " DOMAIN " , NULL , & Query_for_list_of_domains } ,
{ " FUNCTION " , NULL , & Query_for_list_of_functions } ,
2005-08-14 20:49:30 +02:00
{ " GROUP " , Query_for_list_of_roles } ,
2003-10-30 22:37:38 +01:00
{ " LANGUAGE " , Query_for_list_of_languages } ,
{ " INDEX " , NULL , & Query_for_list_of_indexes } ,
2005-10-15 04:49:52 +02:00
{ " OPERATOR " , NULL , NULL } , /* Querying for this is probably not such a
* good idea . */
2005-08-14 20:49:30 +02:00
{ " ROLE " , Query_for_list_of_roles } ,
2003-10-30 22:37:38 +01:00
{ " RULE " , " SELECT pg_catalog.quote_ident(rulename) FROM pg_catalog.pg_rules WHERE substring(pg_catalog.quote_ident(rulename),1,%d)='%s' " } ,
{ " SCHEMA " , Query_for_list_of_schemas } ,
{ " SEQUENCE " , NULL , & Query_for_list_of_sequences } ,
{ " TABLE " , NULL , & Query_for_list_of_tables } ,
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
{ " TABLESPACE " , Query_for_list_of_tablespaces } ,
2004-08-29 07:07:03 +02:00
{ " TEMP " , NULL , NULL } , /* for CREATE TEMP TABLE ... */
2003-10-30 22:37:38 +01:00
{ " TRIGGER " , " SELECT pg_catalog.quote_ident(tgname) FROM pg_catalog.pg_trigger WHERE substring(pg_catalog.quote_ident(tgname),1,%d)='%s' " } ,
{ " TYPE " , NULL , & Query_for_list_of_datatypes } ,
2004-08-29 07:07:03 +02:00
{ " UNIQUE " , NULL , NULL } , /* for CREATE UNIQUE INDEX ... */
2005-08-14 20:49:30 +02:00
{ " USER " , Query_for_list_of_roles } ,
2003-10-30 22:37:38 +01:00
{ " VIEW " , NULL , & Query_for_list_of_views } ,
{ NULL , NULL , NULL } /* end of list */
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
} ;
2003-10-30 22:37:38 +01:00
/* Forward declaration of functions */
static char * * psql_completion ( char * text , int start , int end ) ;
static char * create_command_generator ( const char * text , int state ) ;
2006-04-02 11:02:41 +02:00
static char * drop_command_generator ( const char * text , int state ) ;
2003-10-30 22:37:38 +01:00
static char * complete_from_query ( const char * text , int state ) ;
static char * complete_from_schema_query ( const char * text , int state ) ;
static char * _complete_from_query ( int is_schema_query ,
const char * text , int state ) ;
static char * complete_from_const ( const char * text , int state ) ;
static char * complete_from_list ( const char * text , int state ) ;
static PGresult * exec_query ( const char * query ) ;
static char * previous_word ( int point , int skip ) ;
2006-10-04 02:30:14 +02:00
static int find_open_parenthesis ( int end ) ;
2005-12-08 22:33:58 +01:00
2003-10-30 22:37:38 +01:00
#if 0
static char * quote_file_name ( char * text , int match_type , char * quote_pointer ) ;
static char * dequote_file_name ( char * text , char quote_char ) ;
# endif
/* Initialize the readline library for our purposes. */
void
initialize_readline ( void )
{
2004-08-29 07:07:03 +02:00
rl_readline_name = ( char * ) pset . progname ;
2003-10-30 22:37:38 +01:00
rl_attempted_completion_function = ( void * ) psql_completion ;
rl_basic_word_break_characters = " \t \n @$><=;|&{( " ;
completion_max_records = 1000 ;
/*
2005-10-15 04:49:52 +02:00
* There is a variable rl_completion_query_items for this but apparently
* it ' s not defined everywhere .
2003-10-30 22:37:38 +01:00
*/
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* The completion function. Acc. to readline spec this gets passed the text
entered to far and its start and end in the readline buffer . The return value
is some partially obscure list format that can be generated by the readline
libraries completion_matches ( ) function , so we don ' t have to worry about it .
*/
2000-04-21 05:01:54 +02:00
static char * *
2000-04-12 19:17:23 +02:00
psql_completion ( char * text , int start , int end )
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
{
2000-04-12 19:17:23 +02:00
/* This is the variable we'll return. */
char * * matches = NULL ;
/* These are going to contain some scannage of the input line. */
char * prev_wd ,
* prev2_wd ,
* prev3_wd ,
2004-11-02 17:10:05 +01:00
* prev4_wd ,
* prev5_wd ;
2000-04-12 19:17:23 +02:00
2004-08-29 07:07:03 +02:00
static const char * const sql_commands [ ] = {
2006-04-02 11:02:41 +02:00
" ABORT " , " ALTER " , " ANALYZE " , " BEGIN " , " CHECKPOINT " , " CLOSE " , " CLUSTER " ,
" COMMENT " , " COMMIT " , " COPY " , " CREATE " , " DEALLOCATE " , " DECLARE " ,
2007-04-26 18:13:15 +02:00
" DELETE FROM " , " DISCARD " , " DROP " , " END " , " EXECUTE " , " EXPLAIN " , " FETCH " ,
" GRANT " , " INSERT " , " LISTEN " , " LOAD " , " LOCK " , " MOVE " , " NOTIFY " , " PREPARE " ,
2006-04-02 11:02:41 +02:00
" REASSIGN " , " REINDEX " , " RELEASE " , " RESET " , " REVOKE " , " ROLLBACK " ,
" SAVEPOINT " , " SELECT " , " SET " , " SHOW " , " START " , " TRUNCATE " , " UNLISTEN " ,
" UPDATE " , " VACUUM " , NULL
2000-04-12 19:17:23 +02:00
} ;
2004-08-29 07:07:03 +02:00
static const char * const backslash_commands [ ] = {
2003-08-04 02:43:34 +02:00
" \\ a " , " \\ connect " , " \\ C " , " \\ cd " , " \\ copy " , " \\ copyright " ,
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
" \\ d " , " \\ da " , " \\ db " , " \\ dc " , " \\ dC " , " \\ dd " , " \\ dD " , " \\ df " ,
" \\ dg " , " \\ di " , " \\ dl " , " \\ dn " , " \\ do " , " \\ dp " , " \\ ds " , " \\ dS " ,
" \\ dt " , " \\ dT " , " \\ dv " , " \\ du " ,
Clean up psql:
Add simple ALTER DATABASE, ALTER TRIGGER, CHECK POINT, CREATE
CONVERSION, CREATE DOMAIN, CREATE LANGUAGE, DEALLOCATE, DROP CONVERSION,
DROP DOMAIN, DROP LANGUAGE, EXECUTE, PREPARE
Complete CAST in CREATE CAST and DROP CAST but doesn't suggest what
should follow.
Add many more SET / SHOW variables to the list. Taken from SHOW ALL
output.
Complete a case sensitive search to allow \dD, \dd, \dS, \ds, \h, \H to
complete properly. But there are no matches, then try a case
insensitive search to allow case conversion. Add all missing help
options.
\Q<tab> -> \q
\dD<tab> -> \dD
\dd<tab> -> \dd
\D<tab><tab><tab> -> \d (with listing of \d? commands)
sel<tab> -> SELECT
Rod Taylor
2002-11-15 04:07:52 +01:00
" \\ e " , " \\ echo " , " \\ encoding " ,
" \\ f " , " \\ g " , " \\ h " , " \\ help " , " \\ H " , " \\ i " , " \\ l " ,
2000-04-12 19:17:23 +02:00
" \\ lo_import " , " \\ lo_export " , " \\ lo_list " , " \\ lo_unlink " ,
2007-02-23 19:20:59 +01:00
" \\ o " , " \\ p " , " \\ password " , " \\ prompt " , " \\ pset " , " \\ q " , " \\ qecho " , " \\ r " ,
2006-04-02 11:02:41 +02:00
" \\ set " , " \\ t " , " \\ T " ,
2002-03-05 01:01:03 +01:00
" \\ timing " , " \\ unset " , " \\ x " , " \\ w " , " \\ z " , " \\ ! " , NULL
2000-04-12 19:17:23 +02:00
} ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2000-04-12 19:17:23 +02:00
( void ) end ; /* not used */
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2000-02-20 15:28:28 +01:00
# ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
2000-04-12 19:17:23 +02:00
rl_completion_append_character = ' ' ;
2000-02-20 15:28:28 +01:00
# endif
2000-04-12 19:17:23 +02:00
/* Clear a few things. */
completion_charp = NULL ;
completion_charpp = NULL ;
completion_info_charp = NULL ;
/*
* Scan the input line before our current position for the last four
2005-10-15 04:49:52 +02:00
* words . According to those we ' ll make some smart decisions on what the
* user is probably intending to type . TODO : Use strtokx ( ) to do this .
2000-04-12 19:17:23 +02:00
*/
prev_wd = previous_word ( start , 0 ) ;
prev2_wd = previous_word ( start , 1 ) ;
prev3_wd = previous_word ( start , 2 ) ;
prev4_wd = previous_word ( start , 3 ) ;
2004-11-02 17:10:05 +01:00
prev5_wd = previous_word ( start , 4 ) ;
2000-04-12 19:17:23 +02:00
/* If a backslash command was started, continue */
if ( text [ 0 ] = = ' \\ ' )
COMPLETE_WITH_LIST ( backslash_commands ) ;
/* If no previous word, suggest one of the basic sql commands */
else if ( ! prev_wd )
COMPLETE_WITH_LIST ( sql_commands ) ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2006-04-02 11:02:41 +02:00
/* CREATE */
/* complete with something you can create */
else if ( pg_strcasecmp ( prev_wd , " CREATE " ) = = 0 )
2003-08-04 02:43:34 +02:00
matches = completion_matches ( text , create_command_generator ) ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2006-04-02 11:02:41 +02:00
/* DROP, except ALTER (TABLE|DOMAIN|GROUP) sth DROP */
/* complete with something you can drop */
else if ( pg_strcasecmp ( prev_wd , " DROP " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " TABLE " ) ! = 0 & &
pg_strcasecmp ( prev3_wd , " DOMAIN " ) ! = 0 & &
pg_strcasecmp ( prev3_wd , " GROUP " ) ! = 0 )
matches = completion_matches ( text , drop_command_generator ) ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* ALTER */
2003-08-04 02:43:34 +02:00
/*
2005-10-15 04:49:52 +02:00
* complete with what you can alter ( TABLE , GROUP , USER , . . . ) unless we ' re
* in ALTER TABLE sth ALTER
2003-08-04 02:43:34 +02:00
*/
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " ALTER " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " TABLE " ) ! = 0 )
2000-04-12 19:17:23 +02:00
{
2003-10-30 22:37:38 +01:00
static const char * const list_ALTER [ ] =
2004-09-01 02:10:01 +02:00
{ " AGGREGATE " , " CONVERSION " , " DATABASE " , " DOMAIN " , " FUNCTION " ,
2005-08-14 20:49:30 +02:00
" GROUP " , " INDEX " , " LANGUAGE " , " OPERATOR " , " ROLE " , " SCHEMA " , " SEQUENCE " , " TABLE " ,
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
" TABLESPACE " , " TRIGGER " , " TYPE " , " USER " , NULL } ;
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_LIST ( list_ALTER ) ;
}
2005-08-14 20:49:30 +02:00
/* ALTER AGGREGATE,FUNCTION <name> */
else if ( pg_strcasecmp ( prev3_wd , " ALTER " ) = = 0 & &
2005-10-15 04:49:52 +02:00
( pg_strcasecmp ( prev2_wd , " AGGREGATE " ) = = 0 | |
2005-08-14 20:49:30 +02:00
pg_strcasecmp ( prev2_wd , " FUNCTION " ) = = 0 ) )
{
static const char * const list_ALTERAGG [ ] =
2005-10-15 04:49:52 +02:00
{ " OWNER TO " , " RENAME TO " , " SET SCHEMA " , NULL } ;
2005-08-14 20:49:30 +02:00
2005-10-15 04:49:52 +02:00
COMPLETE_WITH_LIST ( list_ALTERAGG ) ;
2005-08-14 20:49:30 +02:00
}
2004-08-29 07:07:03 +02:00
2005-08-14 20:49:30 +02:00
/* ALTER CONVERSION,SCHEMA <name> */
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " ALTER " ) = = 0 & &
2005-10-15 04:49:52 +02:00
( pg_strcasecmp ( prev2_wd , " CONVERSION " ) = = 0 | |
2004-08-29 07:07:03 +02:00
pg_strcasecmp ( prev2_wd , " SCHEMA " ) = = 0 ) )
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
{
static const char * const list_ALTERGEN [ ] =
{ " OWNER TO " , " RENAME TO " , NULL } ;
COMPLETE_WITH_LIST ( list_ALTERGEN ) ;
}
2001-03-22 05:01:46 +01:00
Clean up psql:
Add simple ALTER DATABASE, ALTER TRIGGER, CHECK POINT, CREATE
CONVERSION, CREATE DOMAIN, CREATE LANGUAGE, DEALLOCATE, DROP CONVERSION,
DROP DOMAIN, DROP LANGUAGE, EXECUTE, PREPARE
Complete CAST in CREATE CAST and DROP CAST but doesn't suggest what
should follow.
Add many more SET / SHOW variables to the list. Taken from SHOW ALL
output.
Complete a case sensitive search to allow \dD, \dd, \dS, \ds, \h, \H to
complete properly. But there are no matches, then try a case
insensitive search to allow case conversion. Add all missing help
options.
\Q<tab> -> \q
\dD<tab> -> \dD
\dd<tab> -> \dd
\D<tab><tab><tab> -> \d (with listing of \d? commands)
sel<tab> -> SELECT
Rod Taylor
2002-11-15 04:07:52 +01:00
/* ALTER DATABASE <name> */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " ALTER " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " DATABASE " ) = = 0 )
Clean up psql:
Add simple ALTER DATABASE, ALTER TRIGGER, CHECK POINT, CREATE
CONVERSION, CREATE DOMAIN, CREATE LANGUAGE, DEALLOCATE, DROP CONVERSION,
DROP DOMAIN, DROP LANGUAGE, EXECUTE, PREPARE
Complete CAST in CREATE CAST and DROP CAST but doesn't suggest what
should follow.
Add many more SET / SHOW variables to the list. Taken from SHOW ALL
output.
Complete a case sensitive search to allow \dD, \dd, \dS, \ds, \h, \H to
complete properly. But there are no matches, then try a case
insensitive search to allow case conversion. Add all missing help
options.
\Q<tab> -> \q
\dD<tab> -> \dD
\dd<tab> -> \dd
\D<tab><tab><tab> -> \d (with listing of \d? commands)
sel<tab> -> SELECT
Rod Taylor
2002-11-15 04:07:52 +01:00
{
2003-10-30 22:37:38 +01:00
static const char * const list_ALTERDATABASE [ ] =
2005-08-14 20:49:30 +02:00
{ " RESET " , " SET " , " OWNER TO " , " RENAME TO " , " CONNECTION LIMIT " , NULL } ;
Clean up psql:
Add simple ALTER DATABASE, ALTER TRIGGER, CHECK POINT, CREATE
CONVERSION, CREATE DOMAIN, CREATE LANGUAGE, DEALLOCATE, DROP CONVERSION,
DROP DOMAIN, DROP LANGUAGE, EXECUTE, PREPARE
Complete CAST in CREATE CAST and DROP CAST but doesn't suggest what
should follow.
Add many more SET / SHOW variables to the list. Taken from SHOW ALL
output.
Complete a case sensitive search to allow \dD, \dd, \dS, \ds, \h, \H to
complete properly. But there are no matches, then try a case
insensitive search to allow case conversion. Add all missing help
options.
\Q<tab> -> \q
\dD<tab> -> \dD
\dd<tab> -> \dd
\D<tab><tab><tab> -> \d (with listing of \d? commands)
sel<tab> -> SELECT
Rod Taylor
2002-11-15 04:07:52 +01:00
COMPLETE_WITH_LIST ( list_ALTERDATABASE ) ;
}
2004-08-21 20:45:59 +02:00
2004-08-20 06:29:33 +02:00
/* ALTER INDEX <name> */
else if ( pg_strcasecmp ( prev3_wd , " ALTER " ) = = 0 & &
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
pg_strcasecmp ( prev2_wd , " INDEX " ) = = 0 )
{
static const char * const list_ALTERINDEX [ ] =
{ " SET TABLESPACE " , " OWNER TO " , " RENAME TO " , NULL } ;
2004-08-29 07:07:03 +02:00
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
COMPLETE_WITH_LIST ( list_ALTERINDEX ) ;
}
2004-09-22 06:25:16 +02:00
/* ALTER LANGUAGE <name> */
else if ( pg_strcasecmp ( prev3_wd , " ALTER " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " LANGUAGE " ) = = 0 )
2007-03-26 18:58:41 +02:00
{
static const char * const list_ALTERLANGUAGE [ ] =
{ " OWNER TO " , " RENAME TO " , NULL } ;
COMPLETE_WITH_LIST ( list_ALTERLANGUAGE ) ;
}
2004-09-22 06:25:16 +02:00
2005-08-14 20:49:30 +02:00
/* ALTER USER,ROLE <name> */
2004-09-22 06:25:16 +02:00
else if ( pg_strcasecmp ( prev3_wd , " ALTER " ) = = 0 & &
2005-08-14 20:49:30 +02:00
( pg_strcasecmp ( prev2_wd , " USER " ) = = 0 | |
2005-10-15 04:49:52 +02:00
pg_strcasecmp ( prev2_wd , " ROLE " ) = = 0 ) )
2004-09-22 06:25:16 +02:00
{
static const char * const list_ALTERUSER [ ] =
{ " ENCRYPTED " , " UNENCRYPTED " , " CREATEDB " , " NOCREATEDB " , " CREATEUSER " ,
2005-10-15 04:49:52 +02:00
" NOCREATEUSER " , " CREATEROLE " , " NOCREATEROLE " , " INHERIT " , " NOINHERIT " ,
" LOGIN " , " NOLOGIN " , " CONNECTION LIMIT " , " VALID UNTIL " , " RENAME TO " ,
" SUPERUSER " , " NOSUPERUSER " , " SET " , " RESET " , NULL } ;
2004-09-22 06:25:16 +02:00
COMPLETE_WITH_LIST ( list_ALTERUSER ) ;
}
2005-08-14 20:49:30 +02:00
/* complete ALTER USER,ROLE <name> ENCRYPTED,UNENCRYPTED with PASSWORD */
else if ( pg_strcasecmp ( prev4_wd , " ALTER " ) = = 0 & &
2005-10-15 04:49:52 +02:00
( pg_strcasecmp ( prev3_wd , " ROLE " ) = = 0 | | pg_strcasecmp ( prev3_wd , " USER " ) = = 0 ) & &
( pg_strcasecmp ( prev_wd , " ENCRYPTED " ) = = 0 | | pg_strcasecmp ( prev_wd , " UNENCRYPTED " ) = = 0 ) )
2005-08-14 20:49:30 +02:00
{
2005-10-15 04:49:52 +02:00
COMPLETE_WITH_CONST ( " PASSWORD " ) ;
2005-08-14 20:49:30 +02:00
}
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
/* ALTER DOMAIN <name> */
else if ( pg_strcasecmp ( prev3_wd , " ALTER " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " DOMAIN " ) = = 0 )
{
static const char * const list_ALTERDOMAIN [ ] =
{ " ADD " , " DROP " , " OWNER TO " , " SET " , NULL } ;
2004-08-20 06:29:33 +02:00
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
COMPLETE_WITH_LIST ( list_ALTERDOMAIN ) ;
}
/* ALTER DOMAIN <sth> DROP */
else if ( pg_strcasecmp ( prev4_wd , " ALTER " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " DOMAIN " ) = = 0 & &
pg_strcasecmp ( prev_wd , " DROP " ) = = 0 )
{
static const char * const list_ALTERDOMAIN2 [ ] =
2004-09-22 06:25:16 +02:00
{ " CONSTRAINT " , " DEFAULT " , " NOT NULL " , NULL } ;
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
COMPLETE_WITH_LIST ( list_ALTERDOMAIN2 ) ;
}
/* ALTER DOMAIN <sth> SET */
else if ( pg_strcasecmp ( prev4_wd , " ALTER " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " DOMAIN " ) = = 0 & &
pg_strcasecmp ( prev_wd , " SET " ) = = 0 )
{
static const char * const list_ALTERDOMAIN3 [ ] =
2005-08-14 20:49:30 +02:00
{ " DEFAULT " , " NOT NULL " , " SCHEMA " , NULL } ;
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
COMPLETE_WITH_LIST ( list_ALTERDOMAIN3 ) ;
}
2004-09-22 06:25:16 +02:00
/* ALTER SEQUENCE <name> */
else if ( pg_strcasecmp ( prev3_wd , " ALTER " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " SEQUENCE " ) = = 0 )
{
2005-10-15 04:49:52 +02:00
static const char * const list_ALTERSEQUENCE [ ] =
{ " INCREMENT " , " MINVALUE " , " MAXVALUE " , " RESTART " , " NO " , " CACHE " , " CYCLE " ,
" SET SCHEMA " , NULL } ;
2004-09-22 06:25:16 +02:00
2005-10-15 04:49:52 +02:00
COMPLETE_WITH_LIST ( list_ALTERSEQUENCE ) ;
2004-09-22 06:25:16 +02:00
}
/* ALTER SEQUENCE <name> NO */
else if ( pg_strcasecmp ( prev4_wd , " ALTER " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " SEQUENCE " ) = = 0 & &
pg_strcasecmp ( prev_wd , " NO " ) = = 0 )
{
2005-10-15 04:49:52 +02:00
static const char * const list_ALTERSEQUENCE2 [ ] =
{ " MINVALUE " , " MAXVALUE " , " CYCLE " , NULL } ;
2004-11-02 17:10:05 +01:00
2005-10-15 04:49:52 +02:00
COMPLETE_WITH_LIST ( list_ALTERSEQUENCE2 ) ;
2004-09-22 06:25:16 +02:00
}
Clean up psql:
Add simple ALTER DATABASE, ALTER TRIGGER, CHECK POINT, CREATE
CONVERSION, CREATE DOMAIN, CREATE LANGUAGE, DEALLOCATE, DROP CONVERSION,
DROP DOMAIN, DROP LANGUAGE, EXECUTE, PREPARE
Complete CAST in CREATE CAST and DROP CAST but doesn't suggest what
should follow.
Add many more SET / SHOW variables to the list. Taken from SHOW ALL
output.
Complete a case sensitive search to allow \dD, \dd, \dS, \ds, \h, \H to
complete properly. But there are no matches, then try a case
insensitive search to allow case conversion. Add all missing help
options.
\Q<tab> -> \q
\dD<tab> -> \dD
\dd<tab> -> \dd
\D<tab><tab><tab> -> \d (with listing of \d? commands)
sel<tab> -> SELECT
Rod Taylor
2002-11-15 04:07:52 +01:00
/* ALTER TRIGGER <name>, add ON */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " ALTER " ) = = 0 & &
2004-09-22 06:25:16 +02:00
pg_strcasecmp ( prev2_wd , " TRIGGER " ) = = 0 )
Clean up psql:
Add simple ALTER DATABASE, ALTER TRIGGER, CHECK POINT, CREATE
CONVERSION, CREATE DOMAIN, CREATE LANGUAGE, DEALLOCATE, DROP CONVERSION,
DROP DOMAIN, DROP LANGUAGE, EXECUTE, PREPARE
Complete CAST in CREATE CAST and DROP CAST but doesn't suggest what
should follow.
Add many more SET / SHOW variables to the list. Taken from SHOW ALL
output.
Complete a case sensitive search to allow \dD, \dd, \dS, \ds, \h, \H to
complete properly. But there are no matches, then try a case
insensitive search to allow case conversion. Add all missing help
options.
\Q<tab> -> \q
\dD<tab> -> \dD
\dd<tab> -> \dd
\D<tab><tab><tab> -> \d (with listing of \d? commands)
sel<tab> -> SELECT
Rod Taylor
2002-11-15 04:07:52 +01:00
COMPLETE_WITH_CONST ( " ON " ) ;
2004-11-02 17:10:05 +01:00
2004-09-22 06:25:16 +02:00
else if ( pg_strcasecmp ( prev4_wd , " ALTER " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " TRIGGER " ) = = 0 )
{
completion_info_charp = prev2_wd ;
COMPLETE_WITH_QUERY ( Query_for_list_of_tables_for_trigger ) ;
}
Clean up psql:
Add simple ALTER DATABASE, ALTER TRIGGER, CHECK POINT, CREATE
CONVERSION, CREATE DOMAIN, CREATE LANGUAGE, DEALLOCATE, DROP CONVERSION,
DROP DOMAIN, DROP LANGUAGE, EXECUTE, PREPARE
Complete CAST in CREATE CAST and DROP CAST but doesn't suggest what
should follow.
Add many more SET / SHOW variables to the list. Taken from SHOW ALL
output.
Complete a case sensitive search to allow \dD, \dd, \dS, \ds, \h, \H to
complete properly. But there are no matches, then try a case
insensitive search to allow case conversion. Add all missing help
options.
\Q<tab> -> \q
\dD<tab> -> \dD
\dd<tab> -> \dd
\D<tab><tab><tab> -> \d (with listing of \d? commands)
sel<tab> -> SELECT
Rod Taylor
2002-11-15 04:07:52 +01:00
/*
* If we have ALTER TRIGGER < sth > ON , then add the correct tablename
*/
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev4_wd , " ALTER " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " TRIGGER " ) = = 0 & &
pg_strcasecmp ( prev_wd , " ON " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables , NULL ) ;
Clean up psql:
Add simple ALTER DATABASE, ALTER TRIGGER, CHECK POINT, CREATE
CONVERSION, CREATE DOMAIN, CREATE LANGUAGE, DEALLOCATE, DROP CONVERSION,
DROP DOMAIN, DROP LANGUAGE, EXECUTE, PREPARE
Complete CAST in CREATE CAST and DROP CAST but doesn't suggest what
should follow.
Add many more SET / SHOW variables to the list. Taken from SHOW ALL
output.
Complete a case sensitive search to allow \dD, \dd, \dS, \ds, \h, \H to
complete properly. But there are no matches, then try a case
insensitive search to allow case conversion. Add all missing help
options.
\Q<tab> -> \q
\dD<tab> -> \dD
\dd<tab> -> \dd
\D<tab><tab><tab> -> \d (with listing of \d? commands)
sel<tab> -> SELECT
Rod Taylor
2002-11-15 04:07:52 +01:00
2004-09-22 06:25:16 +02:00
/* ALTER TRIGGER <name> ON <name> */
else if ( pg_strcasecmp ( prev4_wd , " TRIGGER " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " ON " ) = = 0 )
COMPLETE_WITH_CONST ( " RENAME TO " ) ;
2001-03-22 05:01:46 +01:00
/*
2002-12-13 06:36:24 +01:00
* If we detect ALTER TABLE < name > , suggest either ADD , DROP , ALTER ,
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
* RENAME , CLUSTER ON or OWNER
2001-03-22 05:01:46 +01:00
*/
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " ALTER " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " TABLE " ) = = 0 )
2000-04-12 19:17:23 +02:00
{
2003-10-30 22:37:38 +01:00
static const char * const list_ALTER2 [ ] =
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
{ " ADD " , " ALTER " , " CLUSTER ON " , " DROP " , " RENAME " , " OWNER TO " ,
" SET " , NULL } ;
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_LIST ( list_ALTER2 ) ;
}
2000-06-25 16:25:51 +02:00
/* If we have TABLE <sth> ALTER|RENAME, provide list of columns */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " TABLE " ) = = 0 & &
( pg_strcasecmp ( prev_wd , " ALTER " ) = = 0 | |
pg_strcasecmp ( prev_wd , " RENAME " ) = = 0 ) )
2006-02-12 08:21:40 +01:00
COMPLETE_WITH_ATTR ( prev2_wd , " UNION SELECT 'COLUMN' " ) ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2006-10-04 02:30:14 +02:00
/*
* If we have TABLE < sth > ALTER COLUMN | RENAME COLUMN , provide list of
* columns
*/
2006-02-12 08:21:40 +01:00
else if ( pg_strcasecmp ( prev4_wd , " TABLE " ) = = 0 & &
( pg_strcasecmp ( prev2_wd , " ALTER " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " RENAME " ) = = 0 ) & &
pg_strcasecmp ( prev_wd , " COLUMN " ) = = 0 )
COMPLETE_WITH_ATTR ( prev3_wd , " " ) ;
2006-10-04 02:30:14 +02:00
2004-09-22 06:25:16 +02:00
/* ALTER TABLE xxx RENAME yyy */
else if ( pg_strcasecmp ( prev4_wd , " TABLE " ) = = 0 & &
2005-05-26 00:12:05 +02:00
pg_strcasecmp ( prev2_wd , " RENAME " ) = = 0 & &
pg_strcasecmp ( prev_wd , " TO " ) ! = 0 )
2004-09-22 06:25:16 +02:00
COMPLETE_WITH_CONST ( " TO " ) ;
2006-02-12 08:21:40 +01:00
/* ALTER TABLE xxx RENAME COLUMN yyy */
else if ( pg_strcasecmp ( prev5_wd , " TABLE " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " RENAME " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " COLUMN " ) = = 0 & &
pg_strcasecmp ( prev_wd , " TO " ) ! = 0 )
COMPLETE_WITH_CONST ( " TO " ) ;
2002-12-13 06:36:24 +01:00
/* If we have TABLE <sth> DROP, provide COLUMN or CONSTRAINT */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " TABLE " ) = = 0 & &
pg_strcasecmp ( prev_wd , " DROP " ) = = 0 )
2002-12-13 06:36:24 +01:00
{
2003-10-30 22:37:38 +01:00
static const char * const list_TABLEDROP [ ] =
{ " COLUMN " , " CONSTRAINT " , NULL } ;
2003-08-04 02:43:34 +02:00
2002-12-13 06:36:24 +01:00
COMPLETE_WITH_LIST ( list_TABLEDROP ) ;
}
/* If we have TABLE <sth> DROP COLUMN, provide list of columns */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev4_wd , " TABLE " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " DROP " ) = = 0 & &
pg_strcasecmp ( prev_wd , " COLUMN " ) = = 0 )
2006-02-12 08:21:40 +01:00
COMPLETE_WITH_ATTR ( prev3_wd , " " ) ;
2004-09-22 06:25:16 +02:00
/* ALTER TABLE ALTER [COLUMN] <foo> */
else if ( ( pg_strcasecmp ( prev3_wd , " ALTER " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " COLUMN " ) = = 0 ) | |
( pg_strcasecmp ( prev4_wd , " TABLE " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " ALTER " ) = = 0 ) )
{
/* DROP ... does not work well yet */
2005-10-15 04:49:52 +02:00
static const char * const list_COLUMNALTER [ ] =
2004-09-22 06:25:16 +02:00
{ " TYPE " , " SET DEFAULT " , " DROP DEFAULT " , " SET NOT NULL " ,
2005-10-15 04:49:52 +02:00
" DROP NOT NULL " , " SET STATISTICS " , " SET STORAGE " , NULL } ;
2004-09-22 06:25:16 +02:00
COMPLETE_WITH_LIST ( list_COLUMNALTER ) ;
}
2007-04-08 02:26:34 +02:00
else if ( pg_strcasecmp ( prev3_wd , " TABLE " ) = = 0 )
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
COMPLETE_WITH_CONST ( " ON " ) ;
else if ( pg_strcasecmp ( prev4_wd , " TABLE " ) = = 0 & &
2004-08-29 07:07:03 +02:00
pg_strcasecmp ( prev_wd , " ON " ) = = 0 )
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
{
completion_info_charp = prev3_wd ;
COMPLETE_WITH_QUERY ( Query_for_index_of_table ) ;
}
2005-08-14 20:49:30 +02:00
/* If we have TABLE <sth> SET, provide WITHOUT,TABLESPACE and SCHEMA */
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " TABLE " ) = = 0 & &
pg_strcasecmp ( prev_wd , " SET " ) = = 0 )
{
static const char * const list_TABLESET [ ] =
2005-10-15 04:49:52 +02:00
{ " WITHOUT " , " TABLESPACE " , " SCHEMA " , NULL } ;
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
COMPLETE_WITH_LIST ( list_TABLESET ) ;
}
2004-08-29 07:07:03 +02:00
/* If we have TABLE <sth> SET TABLESPACE provide a list of tablespaces */
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
else if ( pg_strcasecmp ( prev4_wd , " TABLE " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " SET " ) = = 0 & &
pg_strcasecmp ( prev_wd , " TABLESPACE " ) = = 0 )
COMPLETE_WITH_QUERY ( Query_for_list_of_tablespaces ) ;
2004-08-29 07:07:03 +02:00
/* If we have TABLE <sth> SET WITHOUT provide CLUSTER or OIDS */
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
else if ( pg_strcasecmp ( prev4_wd , " TABLE " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " SET " ) = = 0 & &
pg_strcasecmp ( prev_wd , " WITHOUT " ) = = 0 )
2004-08-29 07:07:03 +02:00
{
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
static const char * const list_TABLESET2 [ ] =
{ " CLUSTER " , " OIDS " , NULL } ;
2002-12-13 06:36:24 +01:00
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
COMPLETE_WITH_LIST ( list_TABLESET2 ) ;
}
/* we have ALTER TABLESPACE, so suggest RENAME TO, OWNER TO */
else if ( pg_strcasecmp ( prev3_wd , " ALTER " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " TABLESPACE " ) = = 0 )
{
static const char * const list_ALTERTSPC [ ] =
{ " RENAME TO " , " OWNER TO " , NULL } ;
COMPLETE_WITH_LIST ( list_ALTERTSPC ) ;
}
2005-08-14 20:49:30 +02:00
/* complete ALTER TYPE <foo> with OWNER TO, SET SCHEMA */
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " ALTER " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " TYPE " ) = = 0 )
2005-08-14 20:49:30 +02:00
{
static const char * const list_ALTERTYPE [ ] =
{ " OWNER TO " , " SET SCHEMA " , NULL } ;
2005-10-15 04:49:52 +02:00
2005-08-14 20:49:30 +02:00
COMPLETE_WITH_LIST ( list_ALTERTYPE ) ;
}
2004-09-22 06:25:16 +02:00
/* complete ALTER GROUP <foo> */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " ALTER " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " GROUP " ) = = 0 )
2000-06-25 16:25:51 +02:00
{
2003-10-30 22:37:38 +01:00
static const char * const list_ALTERGROUP [ ] =
2004-09-22 06:25:16 +02:00
{ " ADD USER " , " DROP USER " , " RENAME TO " , NULL } ;
2001-03-22 05:01:46 +01:00
2000-06-25 16:25:51 +02:00
COMPLETE_WITH_LIST ( list_ALTERGROUP ) ;
}
/* complete ALTER GROUP <foo> ADD|DROP with USER */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev4_wd , " ALTER " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " GROUP " ) = = 0 & &
( pg_strcasecmp ( prev_wd , " ADD " ) = = 0 | |
pg_strcasecmp ( prev_wd , " DROP " ) = = 0 ) )
2000-06-25 16:25:51 +02:00
COMPLETE_WITH_CONST ( " USER " ) ;
/* complete {ALTER} GROUP <foo> ADD|DROP USER with a user name */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev4_wd , " GROUP " ) = = 0 & &
( pg_strcasecmp ( prev2_wd , " ADD " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " DROP " ) = = 0 ) & &
pg_strcasecmp ( prev_wd , " USER " ) = = 0 )
2005-08-14 20:49:30 +02:00
COMPLETE_WITH_QUERY ( Query_for_list_of_roles ) ;
2000-06-25 16:25:51 +02:00
2005-07-29 00:14:30 +02:00
/* BEGIN, END, ABORT */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " BEGIN " ) = = 0 | |
2004-08-29 07:07:03 +02:00
pg_strcasecmp ( prev_wd , " END " ) = = 0 | |
pg_strcasecmp ( prev_wd , " ABORT " ) = = 0 )
2004-01-10 03:21:08 +01:00
{
2004-08-29 07:07:03 +02:00
static const char * const list_TRANS [ ] =
2004-01-10 03:21:08 +01:00
{ " WORK " , " TRANSACTION " , NULL } ;
2004-07-27 07:11:48 +02:00
COMPLETE_WITH_LIST ( list_TRANS ) ;
2005-10-15 04:49:52 +02:00
}
2005-07-29 00:14:30 +02:00
/* COMMIT */
2005-10-15 04:49:52 +02:00
else if ( pg_strcasecmp ( prev_wd , " COMMIT " ) = = 0 )
2005-07-29 00:14:30 +02:00
{
static const char * const list_COMMIT [ ] =
{ " WORK " , " TRANSACTION " , " PREPARED " , NULL } ;
COMPLETE_WITH_LIST ( list_COMMIT ) ;
2004-07-27 07:11:48 +02:00
}
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
/* RELEASE SAVEPOINT */
2004-08-29 07:07:03 +02:00
else if ( pg_strcasecmp ( prev_wd , " RELEASE " ) = = 0 )
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
COMPLETE_WITH_CONST ( " SAVEPOINT " ) ;
2004-07-27 07:11:48 +02:00
/* ROLLBACK*/
2004-08-29 07:07:03 +02:00
else if ( pg_strcasecmp ( prev_wd , " ROLLBACK " ) = = 0 )
2004-07-27 07:11:48 +02:00
{
2004-08-29 07:07:03 +02:00
static const char * const list_TRANS [ ] =
2005-07-29 00:14:30 +02:00
{ " WORK " , " TRANSACTION " , " TO SAVEPOINT " , " PREPARED " , NULL } ;
2004-07-27 07:11:48 +02:00
2004-01-10 03:21:08 +01:00
COMPLETE_WITH_LIST ( list_TRANS ) ;
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* CLUSTER */
2004-08-29 07:07:03 +02:00
/*
* If the previous word is CLUSTER and not without produce list of
2007-04-08 02:26:34 +02:00
* tables
2004-08-29 07:07:03 +02:00
*/
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " CLUSTER " ) = = 0 & &
2004-08-29 07:07:03 +02:00
pg_strcasecmp ( prev2_wd , " WITHOUT " ) ! = 0 )
2007-04-08 02:26:34 +02:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables , NULL ) ;
/* If we have CLUSTER <sth>, then add "USING" */
2004-08-29 07:07:03 +02:00
else if ( pg_strcasecmp ( prev2_wd , " CLUSTER " ) = = 0 & &
2007-04-08 02:26:34 +02:00
pg_strcasecmp ( prev_wd , " ON " ) ! = 0 ) {
COMPLETE_WITH_CONST ( " USING " ) ;
}
2000-04-12 19:17:23 +02:00
/*
2007-04-08 02:26:34 +02:00
* If we have CLUSTER < sth > ORDER BY , then add the index as well .
2000-04-12 19:17:23 +02:00
*/
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " CLUSTER " ) = = 0 & &
2007-04-08 02:26:34 +02:00
pg_strcasecmp ( prev_wd , " USING " ) = = 0 )
2000-04-12 19:17:23 +02:00
{
2003-10-15 00:47:12 +02:00
completion_info_charp = prev2_wd ;
2007-04-08 02:26:34 +02:00
COMPLETE_WITH_QUERY ( Query_for_index_of_table ) ;
2000-04-12 19:17:23 +02:00
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2000-06-25 16:25:51 +02:00
/* COMMENT */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " COMMENT " ) = = 0 )
2000-06-25 16:25:51 +02:00
COMPLETE_WITH_CONST ( " ON " ) ;
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev2_wd , " COMMENT " ) = = 0 & &
pg_strcasecmp ( prev_wd , " ON " ) = = 0 )
2000-06-25 16:25:51 +02:00
{
2003-10-30 22:37:38 +01:00
static const char * const list_COMMENT [ ] =
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
{ " CAST " , " CONVERSION " , " DATABASE " , " INDEX " , " LANGUAGE " , " RULE " , " SCHEMA " ,
2004-08-29 07:07:03 +02:00
" SEQUENCE " , " TABLE " , " TYPE " , " VIEW " , " COLUMN " , " AGGREGATE " , " FUNCTION " ,
2006-02-12 04:22:21 +01:00
" OPERATOR " , " TRIGGER " , " CONSTRAINT " , " DOMAIN " , " LARGE OBJECT " ,
2006-10-04 02:30:14 +02:00
" TABLESPACE " , " ROLE " , NULL } ;
2001-03-22 05:01:46 +01:00
2000-06-25 16:25:51 +02:00
COMPLETE_WITH_LIST ( list_COMMENT ) ;
}
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev4_wd , " COMMENT " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " ON " ) = = 0 )
2000-06-25 16:25:51 +02:00
COMPLETE_WITH_CONST ( " IS " ) ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* COPY */
2000-04-12 19:17:23 +02:00
/*
* If we have COPY [ BINARY ] ( which you ' d have to type yourself ) , offer
* list of tables ( Also cover the analogous backslash command )
*/
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " COPY " ) = = 0 | |
pg_strcasecmp ( prev_wd , " \\ copy " ) = = 0 | |
( pg_strcasecmp ( prev2_wd , " COPY " ) = = 0 & &
pg_strcasecmp ( prev_wd , " BINARY " ) = = 0 ) )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables , NULL ) ;
2000-04-12 19:17:23 +02:00
/* If we have COPY|BINARY <sth>, complete it with "TO" or "FROM" */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev2_wd , " COPY " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " \\ copy " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " BINARY " ) = = 0 )
2005-10-15 04:49:52 +02:00
{
static const char * const list_FROMTO [ ] =
{ " FROM " , " TO " , NULL } ;
2004-11-02 17:10:05 +01:00
2005-10-15 04:49:52 +02:00
COMPLETE_WITH_LIST ( list_FROMTO ) ;
}
2004-09-22 06:25:16 +02:00
/* If we have COPY|BINARY <sth> FROM|TO, complete with filename */
else if ( ( pg_strcasecmp ( prev3_wd , " COPY " ) = = 0 | |
pg_strcasecmp ( prev3_wd , " \\ copy " ) = = 0 | |
pg_strcasecmp ( prev3_wd , " BINARY " ) = = 0 ) & &
( pg_strcasecmp ( prev_wd , " FROM " ) = = 0 | |
pg_strcasecmp ( prev_wd , " TO " ) = = 0 ) )
matches = completion_matches ( text , filename_completion_function ) ;
/* Handle COPY|BINARY <sth> FROM|TO filename */
else if ( ( pg_strcasecmp ( prev4_wd , " COPY " ) = = 0 | |
pg_strcasecmp ( prev4_wd , " \\ copy " ) = = 0 | |
pg_strcasecmp ( prev4_wd , " BINARY " ) = = 0 ) & &
( pg_strcasecmp ( prev2_wd , " FROM " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " TO " ) = = 0 ) )
2005-10-15 04:49:52 +02:00
{
static const char * const list_COPY [ ] =
{ " BINARY " , " OIDS " , " DELIMITER " , " NULL " , " CSV " , NULL } ;
2000-04-12 19:17:23 +02:00
2005-10-15 04:49:52 +02:00
COMPLETE_WITH_LIST ( list_COPY ) ;
}
2004-09-22 06:25:16 +02:00
/* Handle COPY|BINARY <sth> FROM|TO filename CSV */
2005-10-15 04:49:52 +02:00
else if ( pg_strcasecmp ( prev_wd , " CSV " ) = = 0 & &
2004-09-22 06:25:16 +02:00
( pg_strcasecmp ( prev3_wd , " FROM " ) = = 0 | |
pg_strcasecmp ( prev3_wd , " TO " ) = = 0 ) )
2005-08-14 20:49:30 +02:00
{
2005-10-15 04:49:52 +02:00
static const char * const list_CSV [ ] =
{ " HEADER " , " QUOTE " , " ESCAPE " , " FORCE QUOTE " , NULL } ;
2004-09-22 06:25:16 +02:00
2005-10-15 04:49:52 +02:00
COMPLETE_WITH_LIST ( list_CSV ) ;
2005-08-14 20:49:30 +02:00
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2005-08-14 20:49:30 +02:00
/* CREATE DATABASE */
else if ( pg_strcasecmp ( prev3_wd , " CREATE " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " DATABASE " ) = = 0 )
{
static const char * const list_DATABASE [ ] =
{ " OWNER " , " TEMPLATE " , " ENCODING " , " TABLESPACE " , " CONNECTION LIMIT " ,
2005-10-15 04:49:52 +02:00
NULL } ;
2005-08-14 20:49:30 +02:00
COMPLETE_WITH_LIST ( list_DATABASE ) ;
}
/* CREATE INDEX */
2000-04-12 19:17:23 +02:00
/* First off we complete CREATE UNIQUE with "INDEX" */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev2_wd , " CREATE " ) = = 0 & &
pg_strcasecmp ( prev_wd , " UNIQUE " ) = = 0 )
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_CONST ( " INDEX " ) ;
/* If we have CREATE|UNIQUE INDEX <sth>, then add "ON" */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev2_wd , " INDEX " ) = = 0 & &
( pg_strcasecmp ( prev3_wd , " CREATE " ) = = 0 | |
pg_strcasecmp ( prev3_wd , " UNIQUE " ) = = 0 ) )
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_CONST ( " ON " ) ;
/* Complete ... INDEX <name> ON with a list of tables */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " INDEX " ) = = 0 & &
pg_strcasecmp ( prev_wd , " ON " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables , NULL ) ;
2000-04-12 19:17:23 +02:00
/*
2005-10-15 04:49:52 +02:00
* Complete INDEX < name > ON < table > with a list of table columns ( which
* should really be in parens )
2000-04-12 19:17:23 +02:00
*/
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev4_wd , " INDEX " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " ON " ) = = 0 )
2005-12-08 22:33:58 +01:00
{
if ( find_open_parenthesis ( end ) )
2006-02-12 08:21:40 +01:00
COMPLETE_WITH_ATTR ( prev_wd , " " ) ;
2005-12-08 22:33:58 +01:00
else
2006-10-04 02:30:14 +02:00
COMPLETE_WITH_CONST ( " ( " ) ;
2005-12-08 22:33:58 +01:00
}
else if ( pg_strcasecmp ( prev5_wd , " INDEX " ) = = 0 & &
2006-10-04 02:30:14 +02:00
pg_strcasecmp ( prev3_wd , " ON " ) = = 0 & &
pg_strcasecmp ( prev_wd , " ( " ) = = 0 )
2006-02-12 08:21:40 +01:00
COMPLETE_WITH_ATTR ( prev2_wd , " " ) ;
2000-04-12 19:17:23 +02:00
/* same if you put in USING */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev4_wd , " ON " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " USING " ) = = 0 )
2006-02-12 08:21:40 +01:00
COMPLETE_WITH_ATTR ( prev3_wd , " " ) ;
2000-04-12 19:17:23 +02:00
/* Complete USING with an index method */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " USING " ) = = 0 )
2000-04-12 19:17:23 +02:00
{
2003-10-30 22:37:38 +01:00
static const char * const index_mth [ ] =
2005-11-07 18:36:47 +01:00
{ " BTREE " , " HASH " , " GIST " , NULL } ;
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_LIST ( index_mth ) ;
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* CREATE RULE */
2000-04-12 19:17:23 +02:00
/* Complete "CREATE RULE <sth>" with "AS" */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " CREATE " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " RULE " ) = = 0 )
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_CONST ( " AS " ) ;
/* Complete "CREATE RULE <sth> AS with "ON" */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev4_wd , " CREATE " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " RULE " ) = = 0 & &
pg_strcasecmp ( prev_wd , " AS " ) = = 0 )
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_CONST ( " ON " ) ;
/* Complete "RULE * AS ON" with SELECT|UPDATE|DELETE|INSERT */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev4_wd , " RULE " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " AS " ) = = 0 & &
pg_strcasecmp ( prev_wd , " ON " ) = = 0 )
2000-04-12 19:17:23 +02:00
{
2003-10-30 22:37:38 +01:00
static const char * const rule_events [ ] =
{ " SELECT " , " UPDATE " , " INSERT " , " DELETE " , NULL } ;
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_LIST ( rule_events ) ;
}
/* Complete "AS ON <sth with a 'T' :)>" with a "TO" */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " AS " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " ON " ) = = 0 & &
2006-09-22 23:39:58 +02:00
( pg_toupper ( ( unsigned char ) prev_wd [ 4 ] ) = = ' T ' | |
pg_toupper ( ( unsigned char ) prev_wd [ 5 ] ) = = ' T ' ) )
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_CONST ( " TO " ) ;
/* Complete "AS ON <sth> TO" with a table name */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev4_wd , " AS " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " ON " ) = = 0 & &
pg_strcasecmp ( prev_wd , " TO " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables , NULL ) ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* CREATE TABLE */
2007-04-27 00:25:56 +02:00
/* Complete "CREATE TEMP/TEMPORARY" with the possible temp objects */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev2_wd , " CREATE " ) = = 0 & &
2007-04-26 20:10:28 +02:00
( pg_strcasecmp ( prev_wd , " TEMP " ) = = 0 | |
pg_strcasecmp ( prev_wd , " TEMPORARY " ) = = 0 ) )
2007-04-27 00:25:56 +02:00
{
static const char * const list_TEMP [ ] =
{ " SEQUENCE " , " TABLE " , " VIEW " , NULL } ;
COMPLETE_WITH_LIST ( list_TEMP ) ;
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2004-11-02 17:10:05 +01:00
/* CREATE TABLESPACE */
else if ( pg_strcasecmp ( prev3_wd , " CREATE " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " TABLESPACE " ) = = 0 )
{
static const char * const list_CREATETABLESPACE [ ] =
{ " OWNER " , " LOCATION " , NULL } ;
COMPLETE_WITH_LIST ( list_CREATETABLESPACE ) ;
}
/* Complete CREATE TABLESPACE name OWNER name with "LOCATION" */
else if ( pg_strcasecmp ( prev5_wd , " CREATE " ) = = 0 & &
pg_strcasecmp ( prev4_wd , " TABLESPACE " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " OWNER " ) = = 0 )
{
COMPLETE_WITH_CONST ( " LOCATION " ) ;
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* CREATE TRIGGER */
2005-08-14 20:49:30 +02:00
/* complete CREATE TRIGGER <name> with BEFORE,AFTER */
else if ( pg_strcasecmp ( prev3_wd , " CREATE " ) = = 0 & &
2005-10-15 04:49:52 +02:00
pg_strcasecmp ( prev2_wd , " TRIGGER " ) = = 0 )
2005-08-14 20:49:30 +02:00
{
static const char * const list_CREATETRIGGER [ ] =
2005-10-15 04:49:52 +02:00
{ " BEFORE " , " AFTER " , NULL } ;
COMPLETE_WITH_LIST ( list_CREATETRIGGER ) ;
2005-08-14 20:49:30 +02:00
}
/* complete CREATE TRIGGER <name> BEFORE,AFTER sth with OR,ON */
else if ( pg_strcasecmp ( prev5_wd , " CREATE " ) = = 0 & &
2005-10-15 04:49:52 +02:00
pg_strcasecmp ( prev4_wd , " TRIGGER " ) = = 0 & &
( pg_strcasecmp ( prev2_wd , " BEFORE " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " AFTER " ) = = 0 ) )
2005-08-14 20:49:30 +02:00
{
static const char * const list_CREATETRIGGER2 [ ] =
2005-10-15 04:49:52 +02:00
{ " ON " , " OR " , NULL } ;
2005-08-14 20:49:30 +02:00
COMPLETE_WITH_LIST ( list_CREATETRIGGER2 ) ;
}
/* CREATE ROLE,USER,GROUP */
else if ( pg_strcasecmp ( prev3_wd , " CREATE " ) = = 0 & &
( pg_strcasecmp ( prev2_wd , " ROLE " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " GROUP " ) = = 0 | | pg_strcasecmp ( prev2_wd , " USER " ) = = 0 ) )
{
static const char * const list_CREATEROLE [ ] =
2005-10-15 04:49:52 +02:00
{ " ADMIN " , " CONNECTION LIMIT " , " CREATEDB " , " CREATEROLE " , " CREATEUSER " ,
" ENCRYPTED " , " IN " , " INHERIT " , " LOGIN " , " NOINHERIT " , " NOLOGIN " , " NOCREATEDB " ,
" NOCREATEROLE " , " NOCREATEUSER " , " NOSUPERUSER " , " ROLE " , " SUPERUSER " , " SYSID " ,
" UNENCRYPTED " , NULL } ;
COMPLETE_WITH_LIST ( list_CREATEROLE ) ;
2005-08-14 20:49:30 +02:00
}
2005-10-15 04:49:52 +02:00
/*
* complete CREATE ROLE , USER , GROUP < name > ENCRYPTED , UNENCRYPTED with
* PASSWORD
*/
2005-08-14 20:49:30 +02:00
else if ( pg_strcasecmp ( prev4_wd , " CREATE " ) = = 0 & &
2005-10-15 04:49:52 +02:00
( pg_strcasecmp ( prev3_wd , " ROLE " ) = = 0 | |
pg_strcasecmp ( prev3_wd , " GROUP " ) = = 0 | | pg_strcasecmp ( prev3_wd , " USER " ) = = 0 ) & &
( pg_strcasecmp ( prev_wd , " ENCRYPTED " ) = = 0 | | pg_strcasecmp ( prev_wd , " UNENCRYPTED " ) = = 0 ) )
2005-08-14 20:49:30 +02:00
{
2005-10-15 04:49:52 +02:00
COMPLETE_WITH_CONST ( " PASSWORD " ) ;
2005-08-14 20:49:30 +02:00
}
/* complete CREATE ROLE,USER,GROUP <name> IN with ROLE,GROUP */
else if ( pg_strcasecmp ( prev4_wd , " CREATE " ) = = 0 & &
2005-10-15 04:49:52 +02:00
( pg_strcasecmp ( prev3_wd , " ROLE " ) = = 0 | |
pg_strcasecmp ( prev3_wd , " GROUP " ) = = 0 | | pg_strcasecmp ( prev3_wd , " USER " ) = = 0 ) & &
pg_strcasecmp ( prev_wd , " IN " ) = = 0 )
2005-08-14 20:49:30 +02:00
{
static const char * const list_CREATEROLE3 [ ] =
2005-10-15 04:49:52 +02:00
{ " GROUP " , " ROLE " , NULL } ;
COMPLETE_WITH_LIST ( list_CREATEROLE3 ) ;
2005-08-14 20:49:30 +02:00
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* CREATE VIEW */
2005-08-14 20:49:30 +02:00
/* Complete CREATE VIEW <name> with AS */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " CREATE " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " VIEW " ) = = 0 )
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_CONST ( " AS " ) ;
/* Complete "CREATE VIEW <sth> AS with "SELECT" */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev4_wd , " CREATE " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " VIEW " ) = = 0 & &
pg_strcasecmp ( prev_wd , " AS " ) = = 0 )
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_CONST ( " SELECT " ) ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2005-05-18 06:47:40 +02:00
/* DECLARE */
else if ( pg_strcasecmp ( prev2_wd , " DECLARE " ) = = 0 )
{
2005-10-15 04:49:52 +02:00
static const char * const list_DECLARE [ ] =
{ " BINARY " , " INSENSITIVE " , " SCROLL " , " NO SCROLL " , " CURSOR " , NULL } ;
COMPLETE_WITH_LIST ( list_DECLARE ) ;
2005-05-18 06:47:40 +02:00
}
else if ( pg_strcasecmp ( prev_wd , " CURSOR " ) = = 0 )
{
2005-10-15 04:49:52 +02:00
static const char * const list_DECLARECURSOR [ ] =
{ " WITH HOLD " , " WITHOUT HOLD " , " FOR " , NULL } ;
COMPLETE_WITH_LIST ( list_DECLARECURSOR ) ;
2005-05-18 06:47:40 +02:00
}
2000-04-12 19:17:23 +02:00
2005-05-18 06:47:40 +02:00
/* DELETE */
2005-10-15 04:49:52 +02:00
2000-04-12 19:17:23 +02:00
/*
* Complete DELETE with FROM ( only if the word before that is not " ON "
2002-06-15 21:43:47 +02:00
* ( cf . rules ) or " BEFORE " or " AFTER " ( cf . triggers ) or GRANT )
2000-04-12 19:17:23 +02:00
*/
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " DELETE " ) = = 0 & &
! ( pg_strcasecmp ( prev2_wd , " ON " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " GRANT " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " BEFORE " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " AFTER " ) = = 0 ) )
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_CONST ( " FROM " ) ;
/* Complete DELETE FROM with a list of tables */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev2_wd , " DELETE " ) = = 0 & &
pg_strcasecmp ( prev_wd , " FROM " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables , NULL ) ;
2005-04-07 03:51:41 +02:00
/* Complete DELETE FROM <table> */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " DELETE " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " FROM " ) = = 0 )
2005-04-07 03:51:41 +02:00
{
static const char * const list_DELETE [ ] =
{ " USING " , " WHERE " , " SET " , NULL } ;
COMPLETE_WITH_LIST ( list_DELETE ) ;
}
/* XXX: implement tab completion for DELETE ... USING */
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2007-04-26 18:13:15 +02:00
/* DISCARD */
else if ( pg_strcasecmp ( prev_wd , " DISCARD " ) = = 0 )
{
static const char * const list_DISCARD [ ] =
{ " ALL " , " PLANS " , " TEMP " , NULL } ;
COMPLETE_WITH_LIST ( list_DISCARD ) ;
}
2005-05-18 06:47:40 +02:00
/* DROP (when not the previous word) */
/* DROP AGGREGATE */
else if ( pg_strcasecmp ( prev3_wd , " DROP " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " AGGREGATE " ) = = 0 )
COMPLETE_WITH_CONST ( " ( " ) ;
/* DROP object with CASCADE / RESTRICT */
else if ( ( pg_strcasecmp ( prev3_wd , " DROP " ) = = 0 & &
( pg_strcasecmp ( prev2_wd , " CONVERSION " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " DOMAIN " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " FUNCTION " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " INDEX " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " LANGUAGE " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " SCHEMA " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " SEQUENCE " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " TABLE " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " TYPE " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " VIEW " ) = = 0 ) ) | |
( pg_strcasecmp ( prev4_wd , " DROP " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " AGGREGATE " ) = = 0 & &
prev_wd [ strlen ( prev_wd ) - 1 ] = = ' ) ' ) )
{
2005-12-08 22:33:58 +01:00
if ( ( pg_strcasecmp ( prev3_wd , " DROP " ) = = 0 ) & & ( pg_strcasecmp ( prev2_wd , " FUNCTION " ) = = 0 ) )
2006-04-02 11:02:41 +02:00
{
if ( find_open_parenthesis ( end ) )
2005-12-08 22:33:58 +01:00
{
static const char func_args_query [ ] = " select pg_catalog.oidvectortypes(proargtypes)||')' from pg_proc where proname='%s' " ;
2006-10-04 02:30:14 +02:00
char * tmp_buf = malloc ( strlen ( func_args_query ) + strlen ( prev_wd ) ) ;
2006-04-02 11:02:41 +02:00
sprintf ( tmp_buf , func_args_query , prev_wd ) ;
COMPLETE_WITH_QUERY ( tmp_buf ) ;
free ( tmp_buf ) ;
2005-12-08 22:33:58 +01:00
}
else
{
2006-04-02 11:02:41 +02:00
COMPLETE_WITH_CONST ( " ( " ) ;
2005-12-08 22:33:58 +01:00
}
2006-04-02 11:02:41 +02:00
}
else
2005-12-08 22:33:58 +01:00
{
static const char * const list_DROPCR [ ] =
{ " CASCADE " , " RESTRICT " , NULL } ;
2006-10-04 02:30:14 +02:00
2005-12-08 22:33:58 +01:00
COMPLETE_WITH_LIST ( list_DROPCR ) ;
}
2005-05-18 06:47:40 +02:00
}
2005-12-08 22:33:58 +01:00
else if ( pg_strcasecmp ( prev4_wd , " DROP " ) = = 0 & &
2006-10-04 02:30:14 +02:00
pg_strcasecmp ( prev3_wd , " FUNCTION " ) = = 0 & &
pg_strcasecmp ( prev_wd , " ( " ) = = 0 )
2005-12-08 22:33:58 +01:00
{
static const char func_args_query [ ] = " select pg_catalog.oidvectortypes(proargtypes)||')' from pg_proc where proname='%s' " ;
2006-10-04 02:30:14 +02:00
char * tmp_buf = malloc ( strlen ( func_args_query ) + strlen ( prev2_wd ) ) ;
2005-12-08 22:33:58 +01:00
sprintf ( tmp_buf , func_args_query , prev2_wd ) ;
COMPLETE_WITH_QUERY ( tmp_buf ) ;
free ( tmp_buf ) ;
}
2006-04-02 11:02:41 +02:00
/* DROP OWNED BY */
else if ( pg_strcasecmp ( prev2_wd , " DROP " ) = = 0 & &
pg_strcasecmp ( prev_wd , " OWNED " ) = = 0 )
COMPLETE_WITH_CONST ( " BY " ) ;
else if ( pg_strcasecmp ( prev3_wd , " DROP " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " OWNED " ) = = 0 & &
pg_strcasecmp ( prev_wd , " BY " ) = = 0 )
COMPLETE_WITH_QUERY ( Query_for_list_of_roles ) ;
2005-12-08 22:33:58 +01:00
2000-04-12 19:17:23 +02:00
2005-05-18 06:47:40 +02:00
/* EXPLAIN */
2005-10-15 04:49:52 +02:00
2000-04-12 19:17:23 +02:00
/*
2005-05-18 06:47:40 +02:00
* Complete EXPLAIN [ ANALYZE ] [ VERBOSE ] with list of EXPLAIN - able commands
2000-04-12 19:17:23 +02:00
*/
2005-05-18 06:47:40 +02:00
else if ( pg_strcasecmp ( prev_wd , " EXPLAIN " ) = = 0 )
{
2005-10-15 04:49:52 +02:00
static const char * const list_EXPLAIN [ ] =
{ " SELECT " , " INSERT " , " DELETE " , " UPDATE " , " DECLARE " , " ANALYZE " , " VERBOSE " , NULL } ;
COMPLETE_WITH_LIST ( list_EXPLAIN ) ;
2005-05-18 06:47:40 +02:00
}
else if ( pg_strcasecmp ( prev2_wd , " EXPLAIN " ) = = 0 & &
2005-10-15 04:49:52 +02:00
pg_strcasecmp ( prev_wd , " ANALYZE " ) = = 0 )
2005-05-18 06:47:40 +02:00
{
2005-10-15 04:49:52 +02:00
static const char * const list_EXPLAIN [ ] =
{ " SELECT " , " INSERT " , " DELETE " , " UPDATE " , " DECLARE " , " VERBOSE " , NULL } ;
COMPLETE_WITH_LIST ( list_EXPLAIN ) ;
2005-05-18 06:47:40 +02:00
}
else if ( pg_strcasecmp ( prev_wd , " VERBOSE " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " VACUUM " ) ! = 0 & &
pg_strcasecmp ( prev4_wd , " VACUUM " ) ! = 0 & &
( pg_strcasecmp ( prev2_wd , " ANALYZE " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " EXPLAIN " ) = = 0 ) )
{
2005-10-15 04:49:52 +02:00
static const char * const list_EXPLAIN [ ] =
{ " SELECT " , " INSERT " , " DELETE " , " UPDATE " , " DECLARE " , NULL } ;
COMPLETE_WITH_LIST ( list_EXPLAIN ) ;
2005-05-18 06:47:40 +02:00
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* FETCH && MOVE */
2000-04-12 19:17:23 +02:00
/* Complete FETCH with one of FORWARD, BACKWARD, RELATIVE */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " FETCH " ) = = 0 | |
pg_strcasecmp ( prev_wd , " MOVE " ) = = 0 )
2000-04-12 19:17:23 +02:00
{
2004-08-29 07:07:03 +02:00
static const char * const list_FETCH1 [ ] =
2005-04-04 09:19:44 +02:00
{ " ABSOLUTE " , " BACKWARD " , " FORWARD " , " RELATIVE " , NULL } ;
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_LIST ( list_FETCH1 ) ;
}
/* Complete FETCH <sth> with one of ALL, NEXT, PRIOR */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev2_wd , " FETCH " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " MOVE " ) = = 0 )
2000-04-12 19:17:23 +02:00
{
2004-08-29 07:07:03 +02:00
static const char * const list_FETCH2 [ ] =
2003-10-30 22:37:38 +01:00
{ " ALL " , " NEXT " , " PRIOR " , NULL } ;
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_LIST ( list_FETCH2 ) ;
}
/*
2005-10-15 04:49:52 +02:00
* Complete FETCH < sth1 > < sth2 > with " FROM " or " IN " . These are equivalent ,
* but we may as well tab - complete both : perhaps some users prefer one
* variant or the other .
2000-04-12 19:17:23 +02:00
*/
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " FETCH " ) = = 0 | |
pg_strcasecmp ( prev3_wd , " MOVE " ) = = 0 )
2000-04-12 19:17:23 +02:00
{
2005-04-04 09:19:44 +02:00
static const char * const list_FROMIN [ ] =
{ " FROM " , " IN " , NULL } ;
2000-04-12 19:17:23 +02:00
2005-04-04 09:19:44 +02:00
COMPLETE_WITH_LIST ( list_FROMIN ) ;
2000-04-12 19:17:23 +02:00
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* GRANT && REVOKE*/
2000-04-12 19:17:23 +02:00
/* Complete GRANT/REVOKE with a list of privileges */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " GRANT " ) = = 0 | |
pg_strcasecmp ( prev_wd , " REVOKE " ) = = 0 )
2000-04-12 19:17:23 +02:00
{
2004-08-29 07:07:03 +02:00
static const char * const list_privileg [ ] =
2003-10-30 22:37:38 +01:00
{ " SELECT " , " INSERT " , " UPDATE " , " DELETE " , " RULE " , " REFERENCES " ,
2006-10-04 02:30:14 +02:00
" TRIGGER " , " CREATE " , " CONNECT " , " TEMPORARY " , " EXECUTE " , " USAGE " ,
" ALL " , NULL } ;
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_LIST ( list_privileg ) ;
}
/* Complete GRANT/REVOKE <sth> with "ON" */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev2_wd , " GRANT " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " REVOKE " ) = = 0 )
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_CONST ( " ON " ) ;
/*
2005-10-15 04:49:52 +02:00
* Complete GRANT / REVOKE < sth > ON with a list of tables , views , sequences ,
* and indexes
2002-08-10 05:56:24 +02:00
*
2005-10-15 04:49:52 +02:00
* keywords DATABASE , FUNCTION , LANGUAGE , SCHEMA added to query result via
* UNION ; seems to work intuitively
2003-08-04 02:43:34 +02:00
*
2005-10-15 04:49:52 +02:00
* Note : GRANT / REVOKE can get quite complex ; tab - completion as implemented
* here will only work if the privilege list contains exactly one
* privilege
2000-04-12 19:17:23 +02:00
*/
2004-05-07 02:24:59 +02:00
else if ( ( pg_strcasecmp ( prev3_wd , " GRANT " ) = = 0 | |
pg_strcasecmp ( prev3_wd , " REVOKE " ) = = 0 ) & &
pg_strcasecmp ( prev_wd , " ON " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tsv ,
2003-10-29 00:35:52 +01:00
" UNION SELECT 'DATABASE' "
" UNION SELECT 'FUNCTION' "
" UNION SELECT 'LANGUAGE' "
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
" UNION SELECT 'SCHEMA' "
" UNION SELECT 'TABLESPACE' " ) ;
2003-03-27 17:45:01 +01:00
/* Complete "GRANT/REVOKE * ON * " with "TO" */
2004-05-07 02:24:59 +02:00
else if ( ( pg_strcasecmp ( prev4_wd , " GRANT " ) = = 0 | |
pg_strcasecmp ( prev4_wd , " REVOKE " ) = = 0 ) & &
pg_strcasecmp ( prev2_wd , " ON " ) = = 0 )
2003-03-27 17:45:01 +01:00
{
2004-05-07 02:24:59 +02:00
if ( pg_strcasecmp ( prev_wd , " DATABASE " ) = = 0 )
2003-03-27 17:45:01 +01:00
COMPLETE_WITH_QUERY ( Query_for_list_of_databases ) ;
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " FUNCTION " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_functions , NULL ) ;
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " LANGUAGE " ) = = 0 )
2003-03-27 17:45:01 +01:00
COMPLETE_WITH_QUERY ( Query_for_list_of_languages ) ;
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " SCHEMA " ) = = 0 )
2003-03-27 17:45:01 +01:00
COMPLETE_WITH_QUERY ( Query_for_list_of_schemas ) ;
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " TABLESPACE " ) = = 0 )
COMPLETE_WITH_QUERY ( Query_for_list_of_tablespaces ) ;
2005-05-18 06:47:40 +02:00
else if ( pg_strcasecmp ( prev4_wd , " GRANT " ) = = 0 )
2003-03-27 17:45:01 +01:00
COMPLETE_WITH_CONST ( " TO " ) ;
2005-05-18 06:47:40 +02:00
else
COMPLETE_WITH_CONST ( " FROM " ) ;
2003-03-27 17:45:01 +01:00
}
2000-04-12 19:17:23 +02:00
2005-05-18 06:47:40 +02:00
/* Complete "GRANT/REVOKE * ON * TO/FROM" with username, GROUP, or PUBLIC */
else if ( pg_strcasecmp ( prev3_wd , " ON " ) = = 0 & &
( ( pg_strcasecmp ( prev5_wd , " GRANT " ) = = 0 & &
pg_strcasecmp ( prev_wd , " TO " ) = = 0 ) | |
( pg_strcasecmp ( prev5_wd , " REVOKE " ) = = 0 & &
pg_strcasecmp ( prev_wd , " FROM " ) = = 0 ) ) )
2005-08-14 20:49:30 +02:00
COMPLETE_WITH_QUERY ( Query_for_list_of_grant_roles ) ;
2005-05-18 06:47:40 +02:00
/* GROUP BY */
else if ( pg_strcasecmp ( prev3_wd , " FROM " ) = = 0 & &
pg_strcasecmp ( prev_wd , " GROUP " ) = = 0 )
COMPLETE_WITH_CONST ( " BY " ) ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* INSERT */
2000-04-12 19:17:23 +02:00
/* Complete INSERT with "INTO" */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " INSERT " ) = = 0 )
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_CONST ( " INTO " ) ;
/* Complete INSERT INTO with table names */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev2_wd , " INSERT " ) = = 0 & &
pg_strcasecmp ( prev_wd , " INTO " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables , NULL ) ;
2002-07-30 18:35:05 +02:00
/* Complete "INSERT INTO <table> (" with attribute names */
2002-12-13 06:36:24 +01:00
else if ( rl_line_buffer [ start - 1 ] = = ' ( ' & &
2004-05-07 02:24:59 +02:00
pg_strcasecmp ( prev3_wd , " INSERT " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " INTO " ) = = 0 )
2006-02-12 08:21:40 +01:00
COMPLETE_WITH_ATTR ( prev_wd , " " ) ;
2001-10-25 07:50:21 +02:00
/*
* Complete INSERT INTO < table > with " VALUES " or " SELECT " or " DEFAULT
* VALUES "
*/
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " INSERT " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " INTO " ) = = 0 )
2000-04-12 19:17:23 +02:00
{
2004-08-29 07:07:03 +02:00
static const char * const list_INSERT [ ] =
2003-10-30 22:37:38 +01:00
{ " DEFAULT VALUES " , " SELECT " , " VALUES " , NULL } ;
2002-09-04 22:31:48 +02:00
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_LIST ( list_INSERT ) ;
}
2002-07-30 18:35:05 +02:00
/* Complete INSERT INTO <table> (attribs) with "VALUES" or "SELECT" */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev4_wd , " INSERT " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " INTO " ) = = 0 & &
2002-09-04 22:31:48 +02:00
prev_wd [ strlen ( prev_wd ) - 1 ] = = ' ) ' )
2002-07-30 18:35:05 +02:00
{
2004-08-29 07:07:03 +02:00
static const char * const list_INSERT [ ] =
2003-10-30 22:37:38 +01:00
{ " SELECT " , " VALUES " , NULL } ;
2002-09-04 22:31:48 +02:00
2002-07-30 18:35:05 +02:00
COMPLETE_WITH_LIST ( list_INSERT ) ;
}
2000-04-12 19:17:23 +02:00
/* Insert an open parenthesis after "VALUES" */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " VALUES " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " DEFAULT " ) ! = 0 )
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_CONST ( " ( " ) ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* LOCK */
2002-07-30 18:35:05 +02:00
/* Complete LOCK [TABLE] with a list of tables */
2006-02-12 08:21:40 +01:00
else if ( pg_strcasecmp ( prev_wd , " LOCK " ) = = 0 )
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables ,
" UNION SELECT 'TABLE' " ) ;
else if ( pg_strcasecmp ( prev_wd , " TABLE " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " LOCK " ) = = 0 )
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables , " " ) ;
2002-07-30 18:35:05 +02:00
/* For the following, handle the case of a single table only for now */
/* Complete LOCK [TABLE] <table> with "IN" */
2004-05-07 02:24:59 +02:00
else if ( ( pg_strcasecmp ( prev2_wd , " LOCK " ) = = 0 & &
pg_strcasecmp ( prev_wd , " TABLE " ) ) | |
( pg_strcasecmp ( prev2_wd , " TABLE " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " LOCK " ) = = 0 ) )
2002-09-04 22:31:48 +02:00
COMPLETE_WITH_CONST ( " IN " ) ;
2002-07-30 18:35:05 +02:00
/* Complete LOCK [TABLE] <table> IN with a lock mode */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " IN " ) = = 0 & &
( pg_strcasecmp ( prev3_wd , " LOCK " ) = = 0 | |
( pg_strcasecmp ( prev3_wd , " TABLE " ) = = 0 & &
pg_strcasecmp ( prev4_wd , " LOCK " ) = = 0 ) ) )
2002-07-30 18:35:05 +02:00
{
2004-08-29 07:07:03 +02:00
static const char * const lock_modes [ ] =
2003-10-30 22:37:38 +01:00
{ " ACCESS SHARE MODE " ,
2004-08-29 07:07:03 +02:00
" ROW SHARE MODE " , " ROW EXCLUSIVE MODE " ,
" SHARE UPDATE EXCLUSIVE MODE " , " SHARE MODE " ,
" SHARE ROW EXCLUSIVE MODE " ,
" EXCLUSIVE MODE " , " ACCESS EXCLUSIVE MODE " , NULL } ;
2002-09-04 22:31:48 +02:00
COMPLETE_WITH_LIST ( lock_modes ) ;
2002-07-30 18:35:05 +02:00
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2000-06-25 16:25:51 +02:00
/* NOTIFY */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " NOTIFY " ) = = 0 )
2003-10-16 22:03:09 +02:00
COMPLETE_WITH_QUERY ( " SELECT pg_catalog.quote_ident(relname) FROM pg_catalog.pg_listener WHERE substring(pg_catalog.quote_ident(relname),1,%d)='%s' " ) ;
2005-05-18 06:47:40 +02:00
2006-04-02 11:02:41 +02:00
/* OWNER TO - complete with available roles */
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
else if ( pg_strcasecmp ( prev2_wd , " OWNER " ) = = 0 & &
2004-08-29 07:07:03 +02:00
pg_strcasecmp ( prev_wd , " TO " ) = = 0 )
2005-08-14 20:49:30 +02:00
COMPLETE_WITH_QUERY ( Query_for_list_of_roles ) ;
2005-05-18 06:47:40 +02:00
/* ORDER BY */
else if ( pg_strcasecmp ( prev3_wd , " FROM " ) = = 0 & &
pg_strcasecmp ( prev_wd , " ORDER " ) = = 0 )
COMPLETE_WITH_CONST ( " BY " ) ;
else if ( pg_strcasecmp ( prev4_wd , " FROM " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " ORDER " ) = = 0 & &
pg_strcasecmp ( prev_wd , " BY " ) = = 0 )
2006-02-12 08:21:40 +01:00
COMPLETE_WITH_ATTR ( prev3_wd , " " ) ;
2005-05-18 06:47:40 +02:00
/* PREPARE xx AS */
else if ( pg_strcasecmp ( prev_wd , " AS " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " PREPARE " ) = = 0 )
{
static const char * const list_PREPARE [ ] =
{ " SELECT " , " UPDATE " , " INSERT " , " DELETE " , NULL } ;
COMPLETE_WITH_LIST ( list_PREPARE ) ;
}
2006-04-02 11:02:41 +02:00
/* REASSIGN OWNED BY xxx TO yyy */
else if ( pg_strcasecmp ( prev_wd , " REASSIGN " ) = = 0 )
COMPLETE_WITH_CONST ( " OWNED " ) ;
else if ( pg_strcasecmp ( prev_wd , " OWNED " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " REASSIGN " ) = = 0 )
COMPLETE_WITH_CONST ( " BY " ) ;
else if ( pg_strcasecmp ( prev_wd , " BY " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " OWNED " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " REASSIGN " ) = = 0 )
COMPLETE_WITH_QUERY ( Query_for_list_of_roles ) ;
else if ( pg_strcasecmp ( prev2_wd , " BY " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " OWNED " ) = = 0 & &
pg_strcasecmp ( prev4_wd , " REASSIGN " ) = = 0 )
COMPLETE_WITH_CONST ( " TO " ) ;
else if ( pg_strcasecmp ( prev_wd , " TO " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " BY " ) = = 0 & &
pg_strcasecmp ( prev4_wd , " OWNED " ) = = 0 & &
pg_strcasecmp ( prev5_wd , " REASSIGN " ) = = 0 )
COMPLETE_WITH_QUERY ( Query_for_list_of_roles ) ;
2005-05-18 06:47:40 +02:00
2000-06-25 16:25:51 +02:00
/* REINDEX */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " REINDEX " ) = = 0 )
2000-06-25 16:25:51 +02:00
{
2004-08-29 07:07:03 +02:00
static const char * const list_REINDEX [ ] =
2005-06-22 23:14:31 +02:00
{ " TABLE " , " INDEX " , " SYSTEM " , " DATABASE " , NULL } ;
2001-03-22 05:01:46 +01:00
2000-06-25 16:25:51 +02:00
COMPLETE_WITH_LIST ( list_REINDEX ) ;
}
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev2_wd , " REINDEX " ) = = 0 )
2000-06-25 16:25:51 +02:00
{
2004-05-07 02:24:59 +02:00
if ( pg_strcasecmp ( prev_wd , " TABLE " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables , NULL ) ;
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " INDEX " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_indexes , NULL ) ;
2005-06-22 23:14:31 +02:00
else if ( pg_strcasecmp ( prev_wd , " SYSTEM " ) = = 0 | |
pg_strcasecmp ( prev_wd , " DATABASE " ) = = 0 )
COMPLETE_WITH_QUERY ( Query_for_list_of_databases ) ;
2000-06-25 16:25:51 +02:00
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* SELECT */
2000-04-12 19:17:23 +02:00
/* naah . . . */
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* SET, RESET, SHOW */
2000-04-12 19:17:23 +02:00
/* Complete with a variable name */
2004-05-07 02:24:59 +02:00
else if ( ( pg_strcasecmp ( prev_wd , " SET " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " UPDATE " ) ! = 0 ) | |
2005-08-14 20:49:30 +02:00
pg_strcasecmp ( prev_wd , " RESET " ) = = 0 )
COMPLETE_WITH_QUERY ( Query_for_list_of_set_vars ) ;
else if ( pg_strcasecmp ( prev_wd , " SHOW " ) = = 0 )
COMPLETE_WITH_QUERY ( Query_for_list_of_show_vars ) ;
2003-01-10 23:03:30 +01:00
/* Complete "SET TRANSACTION" */
2004-05-07 02:24:59 +02:00
else if ( ( pg_strcasecmp ( prev2_wd , " SET " ) = = 0 & &
pg_strcasecmp ( prev_wd , " TRANSACTION " ) = = 0 )
| | ( pg_strcasecmp ( prev2_wd , " START " ) = = 0
& & pg_strcasecmp ( prev_wd , " TRANSACTION " ) = = 0 )
| | ( pg_strcasecmp ( prev2_wd , " BEGIN " ) = = 0
& & pg_strcasecmp ( prev_wd , " WORK " ) = = 0 )
| | ( pg_strcasecmp ( prev2_wd , " BEGIN " ) = = 0
& & pg_strcasecmp ( prev_wd , " TRANSACTION " ) = = 0 )
| | ( pg_strcasecmp ( prev4_wd , " SESSION " ) = = 0
& & pg_strcasecmp ( prev3_wd , " CHARACTERISTICS " ) = = 0
& & pg_strcasecmp ( prev2_wd , " AS " ) = = 0
& & pg_strcasecmp ( prev_wd , " TRANSACTION " ) = = 0 ) )
2003-01-10 23:03:30 +01:00
{
2004-08-29 07:07:03 +02:00
static const char * const my_list [ ] =
2005-05-18 06:47:40 +02:00
{ " ISOLATION LEVEL " , " READ " , NULL } ;
2003-01-10 23:03:30 +01:00
COMPLETE_WITH_LIST ( my_list ) ;
}
2004-05-07 02:24:59 +02:00
else if ( ( pg_strcasecmp ( prev3_wd , " SET " ) = = 0
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
| | pg_strcasecmp ( prev3_wd , " BEGIN " ) = = 0
2004-05-07 02:24:59 +02:00
| | pg_strcasecmp ( prev3_wd , " START " ) = = 0
| | ( pg_strcasecmp ( prev4_wd , " CHARACTERISTICS " ) = = 0
& & pg_strcasecmp ( prev3_wd , " AS " ) = = 0 ) )
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
& & ( pg_strcasecmp ( prev2_wd , " TRANSACTION " ) = = 0
2004-08-29 07:07:03 +02:00
| | pg_strcasecmp ( prev2_wd , " WORK " ) = = 0 )
2004-05-07 02:24:59 +02:00
& & pg_strcasecmp ( prev_wd , " ISOLATION " ) = = 0 )
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_CONST ( " LEVEL " ) ;
2004-05-07 02:24:59 +02:00
else if ( ( pg_strcasecmp ( prev4_wd , " SET " ) = = 0
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
| | pg_strcasecmp ( prev4_wd , " BEGIN " ) = = 0
2004-05-07 02:24:59 +02:00
| | pg_strcasecmp ( prev4_wd , " START " ) = = 0
| | pg_strcasecmp ( prev4_wd , " AS " ) = = 0 )
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
& & ( pg_strcasecmp ( prev3_wd , " TRANSACTION " ) = = 0
2004-08-29 07:07:03 +02:00
| | pg_strcasecmp ( prev3_wd , " WORK " ) = = 0 )
2004-05-07 02:24:59 +02:00
& & pg_strcasecmp ( prev2_wd , " ISOLATION " ) = = 0
& & pg_strcasecmp ( prev_wd , " LEVEL " ) = = 0 )
2000-04-12 19:17:23 +02:00
{
2004-08-29 07:07:03 +02:00
static const char * const my_list [ ] =
2003-11-06 23:08:15 +01:00
{ " READ " , " REPEATABLE " , " SERIALIZABLE " , NULL } ;
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_LIST ( my_list ) ;
}
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
else if ( ( pg_strcasecmp ( prev4_wd , " TRANSACTION " ) = = 0 | |
2004-08-29 07:07:03 +02:00
pg_strcasecmp ( prev4_wd , " WORK " ) = = 0 ) & &
2004-05-07 02:24:59 +02:00
pg_strcasecmp ( prev3_wd , " ISOLATION " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " LEVEL " ) = = 0 & &
pg_strcasecmp ( prev_wd , " READ " ) = = 0 )
2003-11-06 23:08:15 +01:00
{
2004-08-29 07:07:03 +02:00
static const char * const my_list [ ] =
2003-11-06 23:08:15 +01:00
{ " UNCOMMITTED " , " COMMITTED " , NULL } ;
COMPLETE_WITH_LIST ( my_list ) ;
}
2004-08-29 07:07:03 +02:00
else if ( ( pg_strcasecmp ( prev4_wd , " TRANSACTION " ) = = 0 | |
pg_strcasecmp ( prev4_wd , " WORK " ) = = 0 ) & &
2004-05-07 02:24:59 +02:00
pg_strcasecmp ( prev3_wd , " ISOLATION " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " LEVEL " ) = = 0 & &
pg_strcasecmp ( prev_wd , " REPEATABLE " ) = = 0 )
2003-11-06 23:08:15 +01:00
COMPLETE_WITH_CONST ( " READ " ) ;
2004-05-07 02:24:59 +02:00
else if ( ( pg_strcasecmp ( prev3_wd , " SET " ) = = 0 | |
2004-08-29 07:07:03 +02:00
pg_strcasecmp ( prev3_wd , " BEGIN " ) = = 0 | |
pg_strcasecmp ( prev3_wd , " START " ) = = 0 | |
pg_strcasecmp ( prev3_wd , " AS " ) = = 0 ) & &
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
( pg_strcasecmp ( prev2_wd , " TRANSACTION " ) = = 0 | |
2004-08-29 07:07:03 +02:00
pg_strcasecmp ( prev2_wd , " WORK " ) = = 0 ) & &
2004-05-07 02:24:59 +02:00
pg_strcasecmp ( prev_wd , " READ " ) = = 0 )
2003-01-10 23:03:30 +01:00
{
2004-08-29 07:07:03 +02:00
static const char * const my_list [ ] =
2003-10-30 22:37:38 +01:00
{ " ONLY " , " WRITE " , NULL } ;
2003-01-10 23:03:30 +01:00
COMPLETE_WITH_LIST ( my_list ) ;
}
2000-06-25 16:25:51 +02:00
/* Complete SET CONSTRAINTS <foo> with DEFERRED|IMMEDIATE */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " SET " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " CONSTRAINTS " ) = = 0 )
2000-06-25 16:25:51 +02:00
{
2004-08-29 07:07:03 +02:00
static const char * const constraint_list [ ] =
2003-10-30 22:37:38 +01:00
{ " DEFERRED " , " IMMEDIATE " , NULL } ;
2001-03-22 05:01:46 +01:00
2000-06-25 16:25:51 +02:00
COMPLETE_WITH_LIST ( constraint_list ) ;
}
2005-08-14 20:49:30 +02:00
/* Complete SET ROLE */
2005-10-15 04:49:52 +02:00
else if ( pg_strcasecmp ( prev2_wd , " SET " ) = = 0 & &
2005-08-14 20:49:30 +02:00
pg_strcasecmp ( prev_wd , " ROLE " ) = = 0 )
COMPLETE_WITH_QUERY ( Query_for_list_of_roles ) ;
2001-05-08 23:06:43 +02:00
/* Complete SET SESSION with AUTHORIZATION or CHARACTERISTICS... */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev2_wd , " SET " ) = = 0 & &
pg_strcasecmp ( prev_wd , " SESSION " ) = = 0 )
2001-05-08 23:06:43 +02:00
{
2004-08-29 07:07:03 +02:00
static const char * const my_list [ ] =
2003-10-30 22:37:38 +01:00
{ " AUTHORIZATION " , " CHARACTERISTICS AS TRANSACTION " , NULL } ;
2001-05-08 23:06:43 +02:00
COMPLETE_WITH_LIST ( my_list ) ;
}
/* Complete SET SESSION AUTHORIZATION with username */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " SET " ) = = 0
& & pg_strcasecmp ( prev2_wd , " SESSION " ) = = 0
& & pg_strcasecmp ( prev_wd , " AUTHORIZATION " ) = = 0 )
2006-02-12 16:25:04 +01:00
COMPLETE_WITH_QUERY ( Query_for_list_of_roles " UNION SELECT 'DEFAULT' " ) ;
2005-11-18 17:31:11 +01:00
/* Complete RESET SESSION with AUTHORIZATION */
else if ( pg_strcasecmp ( prev2_wd , " RESET " ) = = 0 & &
pg_strcasecmp ( prev_wd , " SESSION " ) = = 0 )
COMPLETE_WITH_CONST ( " AUTHORIZATION " ) ;
2000-04-12 19:17:23 +02:00
/* Complete SET <var> with "TO" */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev2_wd , " SET " ) = = 0 & &
2004-09-22 06:25:16 +02:00
pg_strcasecmp ( prev4_wd , " UPDATE " ) ! = 0 & &
pg_strcasecmp ( prev_wd , " TABLESPACE " ) ! = 0 & &
pg_strcasecmp ( prev4_wd , " DOMAIN " ) ! = 0 )
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_CONST ( " TO " ) ;
/* Suggest possible variable values */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev3_wd , " SET " ) = = 0 & &
2005-10-15 04:49:52 +02:00
( pg_strcasecmp ( prev_wd , " TO " ) = = 0 | | strcmp ( prev_wd , " = " ) = = 0 ) )
2000-04-12 19:17:23 +02:00
{
2004-05-07 02:24:59 +02:00
if ( pg_strcasecmp ( prev2_wd , " DateStyle " ) = = 0 )
2000-04-12 19:17:23 +02:00
{
2004-08-29 07:07:03 +02:00
static const char * const my_list [ ] =
2003-10-30 22:37:38 +01:00
{ " ISO " , " SQL " , " Postgres " , " German " ,
2005-10-15 04:49:52 +02:00
" YMD " , " DMY " , " MDY " ,
" US " , " European " , " NonEuropean " ,
2004-08-29 07:07:03 +02:00
" DEFAULT " , NULL } ;
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_LIST ( my_list ) ;
}
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev2_wd , " GEQO " ) = = 0 )
2000-04-12 19:17:23 +02:00
{
2004-08-29 07:07:03 +02:00
static const char * const my_list [ ] =
2003-10-30 22:37:38 +01:00
{ " ON " , " OFF " , " DEFAULT " , NULL } ;
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_LIST ( my_list ) ;
}
else
{
2004-08-29 07:07:03 +02:00
static const char * const my_list [ ] =
2003-10-30 22:37:38 +01:00
{ " DEFAULT " , NULL } ;
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_LIST ( my_list ) ;
}
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2003-11-06 23:08:15 +01:00
/* START TRANSACTION */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " START " ) = = 0 )
2003-11-06 23:08:15 +01:00
COMPLETE_WITH_CONST ( " TRANSACTION " ) ;
2000-06-25 16:25:51 +02:00
/* TRUNCATE */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " TRUNCATE " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables , NULL ) ;
2000-06-25 16:25:51 +02:00
/* UNLISTEN */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " UNLISTEN " ) = = 0 )
2003-10-16 22:03:09 +02:00
COMPLETE_WITH_QUERY ( " SELECT pg_catalog.quote_ident(relname) FROM pg_catalog.pg_listener WHERE substring(pg_catalog.quote_ident(relname),1,%d)='%s' UNION SELECT '*' " ) ;
2000-06-25 16:25:51 +02:00
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* UPDATE */
2000-04-12 19:17:23 +02:00
/* If prev. word is UPDATE suggest a list of tables */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " UPDATE " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables , NULL ) ;
2000-04-12 19:17:23 +02:00
/* Complete UPDATE <table> with "SET" */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev2_wd , " UPDATE " ) = = 0 )
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_CONST ( " SET " ) ;
/*
2005-10-15 04:49:52 +02:00
* If the previous word is SET ( and it wasn ' t caught above as the _first_
* word ) the word before it was ( hopefully ) a table name and we ' ll now
* make a list of attributes .
2000-04-12 19:17:23 +02:00
*/
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " SET " ) = = 0 )
2006-02-12 08:21:40 +01:00
COMPLETE_WITH_ATTR ( prev2_wd , " " ) ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2005-05-18 06:47:40 +02:00
/* UPDATE xx SET yy = */
else if ( pg_strcasecmp ( prev2_wd , " SET " ) = = 0 & &
2005-10-15 04:49:52 +02:00
pg_strcasecmp ( prev4_wd , " UPDATE " ) = = 0 )
2005-05-18 06:47:40 +02:00
COMPLETE_WITH_CONST ( " = " ) ;
/*
* VACUUM [ FULL | FREEZE ] [ VERBOSE ] [ table ]
* VACUUM [ FULL | FREEZE ] [ VERBOSE ] ANALYZE [ table [ ( column [ , . . . ] ) ] ]
*/
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " VACUUM " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables ,
2003-10-29 00:35:52 +01:00
" UNION SELECT 'FULL' "
2005-05-18 06:47:40 +02:00
" UNION SELECT 'FREEZE' "
2003-10-29 00:35:52 +01:00
" UNION SELECT 'ANALYZE' "
" UNION SELECT 'VERBOSE' " ) ;
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev2_wd , " VACUUM " ) = = 0 & &
( pg_strcasecmp ( prev_wd , " FULL " ) = = 0 | |
2005-05-18 06:47:40 +02:00
pg_strcasecmp ( prev_wd , " FREEZE " ) = = 0 ) )
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables ,
" UNION SELECT 'ANALYZE' "
" UNION SELECT 'VERBOSE' " ) ;
else if ( pg_strcasecmp ( prev3_wd , " VACUUM " ) = = 0 & &
pg_strcasecmp ( prev_wd , " ANALYZE " ) = = 0 & &
( pg_strcasecmp ( prev2_wd , " FULL " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " FREEZE " ) = = 0 ) )
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables ,
" UNION SELECT 'VERBOSE' " ) ;
else if ( pg_strcasecmp ( prev3_wd , " VACUUM " ) = = 0 & &
pg_strcasecmp ( prev_wd , " VERBOSE " ) = = 0 & &
( pg_strcasecmp ( prev2_wd , " FULL " ) = = 0 | |
pg_strcasecmp ( prev2_wd , " FREEZE " ) = = 0 ) )
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables ,
" UNION SELECT 'ANALYZE' " ) ;
else if ( pg_strcasecmp ( prev2_wd , " VACUUM " ) = = 0 & &
pg_strcasecmp ( prev_wd , " VERBOSE " ) = = 0 )
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables ,
" UNION SELECT 'ANALYZE' " ) ;
else if ( pg_strcasecmp ( prev2_wd , " VACUUM " ) = = 0 & &
pg_strcasecmp ( prev_wd , " ANALYZE " ) = = 0 )
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables ,
" UNION SELECT 'VERBOSE' " ) ;
else if ( ( pg_strcasecmp ( prev_wd , " ANALYZE " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " VERBOSE " ) = = 0 ) | |
( pg_strcasecmp ( prev_wd , " VERBOSE " ) = = 0 & &
pg_strcasecmp ( prev2_wd , " ANALYZE " ) = = 0 ) )
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables , NULL ) ;
2005-08-14 20:49:30 +02:00
/* ANALYZE */
2005-05-18 06:47:40 +02:00
/* If the previous word is ANALYZE, produce list of tables */
else if ( pg_strcasecmp ( prev_wd , " ANALYZE " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables , NULL ) ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2002-07-30 18:35:05 +02:00
/* WHERE */
/* Simple case of the word before the where being the table name */
2004-05-07 02:24:59 +02:00
else if ( pg_strcasecmp ( prev_wd , " WHERE " ) = = 0 )
2006-02-12 08:21:40 +01:00
COMPLETE_WITH_ATTR ( prev2_wd , " " ) ;
2002-07-30 18:35:05 +02:00
1999-12-10 04:59:30 +01:00
/* ... FROM ... */
2003-03-27 17:45:01 +01:00
/* TODO: also include SRF ? */
2004-09-22 06:25:16 +02:00
else if ( pg_strcasecmp ( prev_wd , " FROM " ) = = 0 & &
pg_strcasecmp ( prev3_wd , " COPY " ) ! = 0 & &
pg_strcasecmp ( prev3_wd , " \\ copy " ) ! = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tsv , NULL ) ;
1999-12-10 04:59:30 +01:00
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* Backslash commands */
2003-03-27 17:45:01 +01:00
/* TODO: \dc \dd \dl */
2000-04-12 19:17:23 +02:00
else if ( strcmp ( prev_wd , " \\ connect " ) = = 0 | | strcmp ( prev_wd , " \\ c " ) = = 0 )
COMPLETE_WITH_QUERY ( Query_for_list_of_databases ) ;
2003-03-27 17:45:01 +01:00
else if ( strcmp ( prev_wd , " \\ d " ) = = 0 | | strcmp ( prev_wd , " \\ d+ " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tisv , NULL ) ;
2003-03-27 17:45:01 +01:00
else if ( strcmp ( prev_wd , " \\ da " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_aggregates , NULL ) ;
Attached is the third version of my patch that adds/fixes several things
to/in the psql-tabcomplete code. This diff includes the still missing
tab-complete support for TABLESPACE I already sent earlier. New in this
version of the patch is a small adaption of the tab-complete code to
support the adjusted SAVEPOINT-Syntax commited by Tom, as well as
completion of the only half working (and I think only by accident)
tabcomplete-suppport for "BEGIN [ TRANSACTION | WORK ]".
below is a complete list of the things I have changed with this patch:
*) add tablespace support for CREATE/DROP/ALTER and \db
*) sync the list of possible commands following ALTER with the docs (by
adding
AGGREGATE,CONVERSATION,DOMAIN,FUNCTION,LANGUAGE,OPERATOR,SEQUENCE,TABLESPACE
and TYPE)
*) provide a list of valid users after "OWNER TO"
*) tab-complete support for ALTER (AGGREGATE|CONVERSION|FUNCTION)
*) basic tab-complete support for ALTER DOMAIN
*) provide a list of suitable indexes following ALTER TABLE <sth>
CLUSTER ON(?)
*) add "CLUSTER ON" and "SET" to the ALTER TABLE <sth> - tab-complete
list(fixes incorrect/wrong tab-complete with ALTER TABLE <sth> SET
+<TAB> too)
*) provide a list of possible indexes following ALTER TABLE <sth> CLUSTER ON
*) provide list of possible commands(WITHOUT CLUSTER,WITHOUT OIDS,
TABLESPACE) following ALTER TABLE <sth> SET
*) sync "COMMENT ON" with docs by adding "CAST","CONVERSION","FUNCTION"
*) add ABSOLUT to the list of possible commands after FETCH
*) "END" was missing from the sql-commands overview (though it had
completion support!) - i know it's depreciated but we have ABORT and
others still in ...
*) fixes small buglet with ALTER (TRIGGER|CLUSTER) ON autocomplete
(CLUSTER ON +<TAB> would produce CLUSTER ON ON - same for TRIGGER ON)
*) adapt to new SAVEPOINT syntax
*) fix incomplete Support for BEGIN [ TRANSACTION | WORK ]
Stefan Kaltenbrunn
2004-08-20 21:24:59 +02:00
else if ( strcmp ( prev_wd , " \\ db " ) = = 0 )
COMPLETE_WITH_QUERY ( Query_for_list_of_tablespaces ) ;
2003-03-27 17:45:01 +01:00
else if ( strcmp ( prev_wd , " \\ dD " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_domains , NULL ) ;
2003-03-27 17:45:01 +01:00
else if ( strcmp ( prev_wd , " \\ df " ) = = 0 | | strcmp ( prev_wd , " \\ df+ " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_functions , NULL ) ;
2003-03-27 17:45:01 +01:00
else if ( strcmp ( prev_wd , " \\ di " ) = = 0 | | strcmp ( prev_wd , " \\ di+ " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_indexes , NULL ) ;
2003-03-27 17:45:01 +01:00
else if ( strcmp ( prev_wd , " \\ dn " ) = = 0 )
COMPLETE_WITH_QUERY ( Query_for_list_of_schemas ) ;
else if ( strcmp ( prev_wd , " \\ dp " ) = = 0 | | strcmp ( prev_wd , " \\ z " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tsv , NULL ) ;
2003-03-27 17:45:01 +01:00
else if ( strcmp ( prev_wd , " \\ ds " ) = = 0 | | strcmp ( prev_wd , " \\ ds+ " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_sequences , NULL ) ;
2003-03-27 17:45:01 +01:00
else if ( strcmp ( prev_wd , " \\ dS " ) = = 0 | | strcmp ( prev_wd , " \\ dS+ " ) = = 0 )
COMPLETE_WITH_QUERY ( Query_for_list_of_system_relations ) ;
else if ( strcmp ( prev_wd , " \\ dt " ) = = 0 | | strcmp ( prev_wd , " \\ dt+ " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_tables , NULL ) ;
2003-03-27 17:45:01 +01:00
else if ( strcmp ( prev_wd , " \\ dT " ) = = 0 | | strcmp ( prev_wd , " \\ dT+ " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_datatypes , NULL ) ;
2003-03-27 17:45:01 +01:00
else if ( strcmp ( prev_wd , " \\ du " ) = = 0 )
2005-08-14 20:49:30 +02:00
COMPLETE_WITH_QUERY ( Query_for_list_of_roles ) ;
2003-03-27 17:45:01 +01:00
else if ( strcmp ( prev_wd , " \\ dv " ) = = 0 | | strcmp ( prev_wd , " \\ dv+ " ) = = 0 )
2003-10-30 22:37:38 +01:00
COMPLETE_WITH_SCHEMA_QUERY ( Query_for_list_of_views , NULL ) ;
2003-06-12 03:38:08 +02:00
else if ( strcmp ( prev_wd , " \\ encoding " ) = = 0 )
COMPLETE_WITH_QUERY ( Query_for_list_of_encodings ) ;
2000-04-12 19:17:23 +02:00
else if ( strcmp ( prev_wd , " \\ h " ) = = 0 | | strcmp ( prev_wd , " \\ help " ) = = 0 )
COMPLETE_WITH_LIST ( sql_commands ) ;
2005-12-18 03:17:16 +01:00
else if ( strcmp ( prev_wd , " \\ password " ) = = 0 )
COMPLETE_WITH_QUERY ( Query_for_list_of_roles ) ;
2000-04-12 19:17:23 +02:00
else if ( strcmp ( prev_wd , " \\ pset " ) = = 0 )
{
2004-08-29 07:07:03 +02:00
static const char * const my_list [ ] =
2003-10-30 22:37:38 +01:00
{ " format " , " border " , " expanded " ,
2004-08-29 07:07:03 +02:00
" null " , " fieldsep " , " tuples_only " , " title " , " tableattr " , " pager " ,
" recordsep " , NULL } ;
2000-04-12 19:17:23 +02:00
COMPLETE_WITH_LIST ( my_list ) ;
}
2001-05-07 21:31:33 +02:00
else if ( strcmp ( prev_wd , " \\ cd " ) = = 0 | |
2005-10-15 04:49:52 +02:00
strcmp ( prev_wd , " \\ e " ) = = 0 | | strcmp ( prev_wd , " \\ edit " ) = = 0 | |
2000-04-12 19:17:23 +02:00
strcmp ( prev_wd , " \\ g " ) = = 0 | |
2005-10-15 04:49:52 +02:00
strcmp ( prev_wd , " \\ i " ) = = 0 | | strcmp ( prev_wd , " \\ include " ) = = 0 | |
strcmp ( prev_wd , " \\ o " ) = = 0 | | strcmp ( prev_wd , " \\ out " ) = = 0 | |
2000-04-12 19:17:23 +02:00
strcmp ( prev_wd , " \\ s " ) = = 0 | |
2005-10-15 04:49:52 +02:00
strcmp ( prev_wd , " \\ w " ) = = 0 | | strcmp ( prev_wd , " \\ write " ) = = 0
2000-04-12 19:17:23 +02:00
)
matches = completion_matches ( text , filename_completion_function ) ;
2005-11-14 18:48:43 +01:00
/*
* Finally , we look through the list of " things " , such as TABLE , INDEX and
* check if that was the previous word . If so , execute the query to get a
* list of them .
*/
2000-04-12 19:17:23 +02:00
else
{
int i ;
for ( i = 0 ; words_after_create [ i ] . name ; i + + )
2003-10-30 22:37:38 +01:00
{
2004-05-07 02:24:59 +02:00
if ( pg_strcasecmp ( prev_wd , words_after_create [ i ] . name ) = = 0 )
2000-04-12 19:17:23 +02:00
{
2003-10-30 22:37:38 +01:00
if ( words_after_create [ i ] . query )
2003-03-27 17:45:01 +01:00
COMPLETE_WITH_QUERY ( words_after_create [ i ] . query ) ;
2003-10-30 22:37:38 +01:00
else if ( words_after_create [ i ] . squery )
COMPLETE_WITH_SCHEMA_QUERY ( * words_after_create [ i ] . squery ,
NULL ) ;
2000-04-12 19:17:23 +02:00
break ;
}
2003-10-30 22:37:38 +01:00
}
2000-04-12 19:17:23 +02:00
}
2005-11-14 18:48:43 +01:00
/*
* If we still don ' t have anything to match we have to fabricate some sort
* of default list . If we were to just return NULL , readline automatically
* attempts filename completion , and that ' s usually no good .
*/
if ( matches = = NULL )
{
COMPLETE_WITH_CONST ( " " ) ;
2000-01-22 00:32:36 +01:00
# ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
2005-11-14 18:48:43 +01:00
rl_completion_append_character = ' \0 ' ;
2000-01-22 00:32:36 +01:00
# endif
2005-11-14 18:48:43 +01:00
}
/* free storage */
free ( prev_wd ) ;
free ( prev2_wd ) ;
free ( prev3_wd ) ;
free ( prev4_wd ) ;
free ( prev5_wd ) ;
/* Return our Grand List O' Matches */
return matches ;
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* GENERATOR FUNCTIONS
These functions do all the actual work of completing the input . They get
passed the text so far and the count how many times they have been called so
far with the same text .
If you read the above carefully , you ' ll see that these don ' t get called
directly but through the readline interface .
The return value is expected to be the full completion of the text , going
through a list each time , or NULL if there are no more matches . The string
2003-12-01 23:14:40 +01:00
will be free ( ) ' d by readline , so you must run it through strdup ( ) or
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
something of that sort .
*/
2006-04-02 11:02:41 +02:00
/* This one gives you one from a list of things you can put after CREATE
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
as defined above .
*/
2005-11-14 18:48:43 +01:00
static char *
create_command_generator ( const char * text , int state )
{
static int list_index ,
string_length ;
const char * name ;
/* If this is the first time for this completion, init some values */
if ( state = = 0 )
{
list_index = 0 ;
string_length = strlen ( text ) ;
}
/* find something that matches */
while ( ( name = words_after_create [ list_index + + ] . name ) )
if ( pg_strncasecmp ( name , text , string_length ) = = 0 )
return pg_strdup ( name ) ;
/* if nothing matches, return NULL */
return NULL ;
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2006-04-02 11:02:41 +02:00
/*
* This function gives you a list of things you can put after a DROP command .
* Very similar to create_command_generator , but has an additional entry for
* OWNED BY . ( We do it this way in order not to duplicate the
* words_after_create list . )
*/
static char *
drop_command_generator ( const char * text , int state )
{
static int list_index ,
string_length ;
const char * name ;
if ( state = = 0 )
{
/* If this is the first time for this completion, init some values */
list_index = 0 ;
string_length = strlen ( text ) ;
/*
* DROP can be followed by " OWNED BY " , which is not found in the list
* for CREATE matches , so make it the first state . ( We do not make it
* the last state because it would be more difficult to detect when we
* have to return NULL instead . )
*
* Make sure we advance to the next state .
*/
list_index + + ;
if ( pg_strncasecmp ( " OWNED " , text , string_length ) = = 0 )
return pg_strdup ( " OWNED " ) ;
}
/*
* In subsequent attempts , try to complete with the same items we use for
* CREATE
*/
while ( ( name = words_after_create [ list_index + + - 1 ] . name ) )
{
if ( pg_strncasecmp ( name , text , string_length ) = = 0 )
return pg_strdup ( name ) ;
}
/* if nothing matches, return NULL */
return NULL ;
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2003-03-27 17:45:01 +01:00
/* The following two functions are wrappers for _complete_from_query */
2005-11-14 18:48:43 +01:00
static char *
complete_from_query ( const char * text , int state )
{
return _complete_from_query ( 0 , text , state ) ;
}
2003-03-27 17:45:01 +01:00
2005-11-14 18:48:43 +01:00
static char *
complete_from_schema_query ( const char * text , int state )
{
return _complete_from_query ( 1 , text , state ) ;
}
2003-03-27 17:45:01 +01:00
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* This creates a list of matching things, according to a query pointed to
2003-03-27 17:45:01 +01:00
by completion_charp .
The query can be one of two kinds :
2003-08-04 02:43:34 +02:00
- A simple query which must contain a % d and a % s , which will be replaced
2003-03-27 17:45:01 +01:00
by the string length of the text and the text itself . The query may also
2003-08-04 02:43:34 +02:00
have another % s in it , which will be replaced by the value of
2003-03-27 17:45:01 +01:00
completion_info_charp .
2003-08-04 02:43:34 +02:00
or :
2003-03-27 17:45:01 +01:00
- A schema query used for completion of both schema and relation names ;
these are more complex and must contain in the following order :
2003-08-04 02:43:34 +02:00
% d % s % d % s % d % s % s % d % s
2003-03-27 17:45:01 +01:00
where % d is the string length of the text and % s the text itself .
2003-10-15 00:47:12 +02:00
It is assumed that strings should be escaped to become SQL literals
( that is , what is in the query is actually . . . ' % s ' . . . )
2003-03-27 17:45:01 +01:00
See top of file for examples of both kinds of query .
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
*/
2003-03-27 17:45:01 +01:00
2005-11-14 18:48:43 +01:00
static char *
_complete_from_query ( int is_schema_query , const char * text , int state )
{
static int list_index ,
string_length ;
static PGresult * result = NULL ;
/*
* If this is the first time for this completion , we fetch a list of our
* " things " from the backend .
*/
if ( state = = 0 )
{
PQExpBufferData query_buffer ;
char * e_text ;
char * e_info_charp ;
list_index = 0 ;
string_length = strlen ( text ) ;
/* Free any prior result */
PQclear ( result ) ;
result = NULL ;
/* Set up suitably-escaped copies of textual inputs */
e_text = pg_malloc ( string_length * 2 + 1 ) ;
PQescapeString ( e_text , text , string_length ) ;
if ( completion_info_charp )
{
size_t charp_len ;
charp_len = strlen ( completion_info_charp ) ;
e_info_charp = pg_malloc ( charp_len * 2 + 1 ) ;
PQescapeString ( e_info_charp , completion_info_charp ,
charp_len ) ;
}
else
e_info_charp = NULL ;
initPQExpBuffer ( & query_buffer ) ;
if ( is_schema_query )
{
/* completion_squery gives us the pieces to assemble */
const char * qualresult = completion_squery - > qualresult ;
if ( qualresult = = NULL )
qualresult = completion_squery - > result ;
/* Get unqualified names matching the input-so-far */
appendPQExpBuffer ( & query_buffer , " SELECT %s FROM %s WHERE " ,
completion_squery - > result ,
completion_squery - > catname ) ;
if ( completion_squery - > selcondition )
appendPQExpBuffer ( & query_buffer , " %s AND " ,
completion_squery - > selcondition ) ;
appendPQExpBuffer ( & query_buffer , " substring(%s,1,%d)='%s' " ,
completion_squery - > result ,
string_length , e_text ) ;
appendPQExpBuffer ( & query_buffer , " AND %s " ,
completion_squery - > viscondition ) ;
/*
* When fetching relation names , suppress system catalogs unless
* the input - so - far begins with " pg_ " . This is a compromise
* between not offering system catalogs for completion at all , and
* having them swamp the result when the input is just " p " .
*/
if ( strcmp ( completion_squery - > catname ,
" pg_catalog.pg_class c " ) = = 0 & &
strncmp ( text , " pg_ " , 3 ) ! = 0 )
{
appendPQExpBuffer ( & query_buffer ,
" AND c.relnamespace <> (SELECT oid FROM "
" pg_catalog.pg_namespace WHERE nspname = 'pg_catalog') " ) ;
}
/*
* Add in matching schema names , but only if there is more than
* one potential match among schema names .
*/
appendPQExpBuffer ( & query_buffer , " \n UNION \n "
" SELECT pg_catalog.quote_ident(n.nspname) || '.' "
" FROM pg_catalog.pg_namespace n "
" WHERE substring(pg_catalog.quote_ident(n.nspname) || '.',1,%d)='%s' " ,
string_length , e_text ) ;
appendPQExpBuffer ( & query_buffer ,
" AND (SELECT pg_catalog.count(*) "
" FROM pg_catalog.pg_namespace "
" WHERE substring(pg_catalog.quote_ident(nspname) || '.',1,%d) = "
" substring('%s',1,pg_catalog.length(pg_catalog.quote_ident(nspname))+1)) > 1 " ,
string_length , e_text ) ;
/*
* Add in matching qualified names , but only if there is exactly
* one schema matching the input - so - far .
*/
appendPQExpBuffer ( & query_buffer , " \n UNION \n "
" SELECT pg_catalog.quote_ident(n.nspname) || '.' || %s "
" FROM %s, pg_catalog.pg_namespace n "
" WHERE %s = n.oid AND " ,
qualresult ,
completion_squery - > catname ,
completion_squery - > namespace ) ;
if ( completion_squery - > selcondition )
appendPQExpBuffer ( & query_buffer , " %s AND " ,
completion_squery - > selcondition ) ;
appendPQExpBuffer ( & query_buffer , " substring(pg_catalog.quote_ident(n.nspname) || '.' || %s,1,%d)='%s' " ,
qualresult ,
string_length , e_text ) ;
/*
* This condition exploits the single - matching - schema rule to
* speed up the query
*/
appendPQExpBuffer ( & query_buffer ,
" AND substring(pg_catalog.quote_ident(n.nspname) || '.',1,%d) = "
" substring('%s',1,pg_catalog.length(pg_catalog.quote_ident(n.nspname))+1) " ,
string_length , e_text ) ;
appendPQExpBuffer ( & query_buffer ,
" AND (SELECT pg_catalog.count(*) "
" FROM pg_catalog.pg_namespace "
" WHERE substring(pg_catalog.quote_ident(nspname) || '.',1,%d) = "
" substring('%s',1,pg_catalog.length(pg_catalog.quote_ident(nspname))+1)) = 1 " ,
string_length , e_text ) ;
/* If an addon query was provided, use it */
if ( completion_charp )
appendPQExpBuffer ( & query_buffer , " \n %s " , completion_charp ) ;
}
else
{
/* completion_charp is an sprintf-style format string */
appendPQExpBuffer ( & query_buffer , completion_charp ,
string_length , e_text , e_info_charp ) ;
}
/* Limit the number of records in the result */
appendPQExpBuffer ( & query_buffer , " \n LIMIT %d " ,
completion_max_records ) ;
result = exec_query ( query_buffer . data ) ;
termPQExpBuffer ( & query_buffer ) ;
free ( e_text ) ;
if ( e_info_charp )
free ( e_info_charp ) ;
}
/* Find something that matches */
if ( result & & PQresultStatus ( result ) = = PGRES_TUPLES_OK )
{
const char * item ;
while ( list_index < PQntuples ( result ) & &
( item = PQgetvalue ( result , list_index + + , 0 ) ) )
if ( pg_strncasecmp ( text , item , string_length ) = = 0 )
return pg_strdup ( item ) ;
}
/* If nothing matches, free the db structure and return null */
PQclear ( result ) ;
result = NULL ;
return NULL ;
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* This function returns in order one of a fixed, NULL pointer terminated list
of strings ( if matching ) . This can be used if there are only a fixed number
SQL words that can appear at certain spot .
*/
2005-11-14 18:48:43 +01:00
static char *
complete_from_list ( const char * text , int state )
{
static int string_length ,
list_index ,
matches ;
static bool casesensitive ;
const char * item ;
/* need to have a list */
psql_assert ( completion_charpp ) ;
/* Initialization */
if ( state = = 0 )
{
list_index = 0 ;
string_length = strlen ( text ) ;
casesensitive = true ;
matches = 0 ;
}
while ( ( item = completion_charpp [ list_index + + ] ) )
{
/* First pass is case sensitive */
if ( casesensitive & & strncmp ( text , item , string_length ) = = 0 )
{
matches + + ;
return pg_strdup ( item ) ;
}
/* Second pass is case insensitive, don't bother counting matches */
if ( ! casesensitive & & pg_strncasecmp ( text , item , string_length ) = = 0 )
return pg_strdup ( item ) ;
}
/*
* No matches found . If we ' re not case insensitive already , lets switch to
* being case insensitive and try again
*/
if ( casesensitive & & matches = = 0 )
{
casesensitive = false ;
list_index = 0 ;
state + + ;
2006-01-11 09:43:13 +01:00
return complete_from_list ( text , state ) ;
2005-11-14 18:48:43 +01:00
}
/* If no more matches, return null. */
return NULL ;
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* This function returns one fixed string the first time even if it doesn't
match what ' s there , and nothing the second time . This should be used if there
is only one possibility that can appear at a certain spot , so misspellings
will be overwritten .
The string to be passed must be in completion_charp .
*/
2005-11-14 18:48:43 +01:00
static char *
complete_from_const ( const char * text , int state )
{
( void ) text ; /* We don't care about what was entered
* already . */
2000-04-12 19:17:23 +02:00
2005-11-14 18:48:43 +01:00
psql_assert ( completion_charp ) ;
if ( state = = 0 )
return pg_strdup ( completion_charp ) ;
else
return NULL ;
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
/* HELPER FUNCTIONS */
2003-10-30 22:37:38 +01:00
/*
* Execute a query and report any errors . This should be the preferred way of
* talking to the database in this file .
*/
2005-11-14 18:48:43 +01:00
static PGresult *
exec_query ( const char * query )
{
PGresult * result ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2005-11-14 18:48:43 +01:00
if ( query = = NULL | | ! pset . db | | PQstatus ( pset . db ) ! = CONNECTION_OK )
return NULL ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2005-11-14 18:48:43 +01:00
result = PQexec ( pset . db , query ) ;
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2005-11-14 18:48:43 +01:00
if ( result ! = NULL & & PQresultStatus ( result ) ! = PGRES_TUPLES_OK )
{
2000-01-19 00:30:24 +01:00
#if 0
2005-11-14 18:48:43 +01:00
psql_error ( " tab completion: %s failed - %s \n " ,
query , PQresStatus ( PQresultStatus ( result ) ) ) ;
2000-01-12 20:36:36 +01:00
# endif
2005-11-14 18:48:43 +01:00
PQclear ( result ) ;
result = NULL ;
}
2000-04-12 19:17:23 +02:00
2005-11-14 18:48:43 +01:00
return result ;
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2005-05-18 07:01:10 +02:00
/*
* Return the word ( space delimited ) before point . Set skip > 0 to
* skip that many words ; e . g . skip = 1 finds the word before the
* previous one . Return value is NULL or a malloc ' ed string .
*/
2005-11-14 18:48:43 +01:00
static char *
previous_word ( int point , int skip )
{
int i ,
start = 0 ,
end = - 1 ,
inquotes = 0 ;
char * s ;
while ( skip - - > = 0 )
{
/* first we look for a space before the current word */
for ( i = point ; i > = 0 ; i - - )
if ( rl_line_buffer [ i ] = = ' ' )
break ;
/* now find the first non-space which then constitutes the end */
for ( ; i > = 0 ; i - - )
if ( rl_line_buffer [ i ] ! = ' ' )
{
end = i ;
break ;
}
/*
* If no end found we return null , because there is no word before the
* point
*/
if ( end = = - 1 )
return NULL ;
/*
* Otherwise we now look for the start . The start is either the last
* character before any space going backwards from the end , or it ' s
* simply character 0
*/
for ( start = end ; start > 0 ; start - - )
{
if ( rl_line_buffer [ start ] = = ' " ' )
inquotes = ! inquotes ;
if ( ( rl_line_buffer [ start - 1 ] = = ' ' ) & & inquotes = = 0 )
break ;
}
point = start ;
}
/* make a copy */
s = pg_malloc ( end - start + 2 ) ;
2007-02-07 01:52:35 +01:00
strlcpy ( s , & rl_line_buffer [ start ] , end - start + 2 ) ;
2005-11-14 18:48:43 +01:00
return s ;
}
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2005-12-08 22:33:58 +01:00
/* Find the parenthesis after the last word */
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
1999-11-26 05:24:17 +01:00
2006-10-04 02:30:14 +02:00
static int
find_open_parenthesis ( int end )
2005-12-08 22:33:58 +01:00
{
2006-10-04 02:30:14 +02:00
int i = end - 1 ;
while ( ( rl_line_buffer [ i ] ! = ' ' ) & & ( i > = 0 ) )
2005-12-08 22:33:58 +01:00
{
2006-10-04 02:30:14 +02:00
if ( rl_line_buffer [ i ] = = ' ( ' )
return 1 ;
2005-12-08 22:33:58 +01:00
i - - ;
}
2006-10-04 02:30:14 +02:00
while ( ( rl_line_buffer [ i ] = = ' ' ) & & ( i > = 0 ) )
2005-12-08 22:33:58 +01:00
{
i - - ;
}
2006-10-04 02:30:14 +02:00
if ( rl_line_buffer [ i ] = = ' ( ' )
2005-12-08 22:33:58 +01:00
{
2006-10-04 02:30:14 +02:00
return 1 ;
2005-12-08 22:33:58 +01:00
}
return 0 ;
}
2000-01-12 20:36:36 +01:00
2000-01-19 00:30:24 +01:00
#if 0
2000-01-12 20:36:36 +01:00
2000-01-19 00:30:24 +01:00
/*
* Surround a string with single quotes . This works for both SQL and
2003-12-01 23:14:40 +01:00
* psql internal . Currently disabled because it is reported not to
2000-01-19 00:30:24 +01:00
* cooperate with certain versions of readline .
*/
2005-11-14 18:48:43 +01:00
static char *
quote_file_name ( char * text , int match_type , char * quote_pointer )
{
char * s ;
size_t length ;
( void ) quote_pointer ; /* not used */
length = strlen ( text ) + ( match_type = = SINGLE_MATCH ? 3 : 2 ) ;
s = pg_malloc ( length ) ;
s [ 0 ] = ' \' ' ;
strcpy ( s + 1 , text ) ;
if ( match_type = = SINGLE_MATCH )
s [ length - 2 ] = ' \' ' ;
s [ length - 1 ] = ' \0 ' ;
return s ;
}
static char *
dequote_file_name ( char * text , char quote_char )
{
char * s ;
size_t length ;
if ( ! quote_char )
return pg_strdup ( text ) ;
length = strlen ( text ) ;
s = pg_malloc ( length - 2 + 1 ) ;
2007-02-07 01:52:35 +01:00
strlcpy ( s , text + 1 , length - 2 + 1 ) ;
2005-11-14 18:48:43 +01:00
return s ;
}
2001-11-05 18:46:40 +01:00
# endif /* 0 */
2001-10-28 07:26:15 +01:00
2001-11-05 18:46:40 +01:00
# endif /* USE_READLINE */