mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Commit of a *MAJOR* patch from Dan McGuirk <djm@indirect.com>
Changes: * Unique index capability works using the syntax 'create unique index'. * Duplicate OID's in the system tables are removed. I put little scripts called 'duplicate_oids' and 'find_oid' in include/catalog that help to find and remove duplicate OID's. I also moved 'unused_oids' from backend/catalog to include/catalog, since it has to be in the same directory as the include files in order to work. * The backend tries converting the name of a function or aggregate to all lowercase if the original name given doesn't work (mostly for compatibility with ODBC). * You can 'SELECT NULL' to your heart's content. * I put my _bt_updateitem fix in instead, which uses _bt_insertonpg so that even if the new key is so big that the page has to be split, everything still works. * All literal references to system catalog OID's have been replaced with references to define'd constants from the catalog header files. * I added a couple of node copy functions. I think this was a preliminary attempt to get rules to work.
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.14 1996/11/10 03:01:10 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.15 1996/11/13 20:48:55 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -77,6 +77,9 @@ static void AddAggToParseState(ParseState *pstate, Aggreg *aggreg);
|
||||
static void finalizeAggregates(ParseState *pstate, Query *qry);
|
||||
static void parseCheckAggregates(ParseState *pstate, Query *qry);
|
||||
|
||||
static bool is_lowercase(char *string);
|
||||
static void make_lowercase(char *string);
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
*****************************************************************************/
|
||||
@ -1869,6 +1872,30 @@ ParseComplexProjection(ParseState *pstate,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool is_lowercase(char *string)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < strlen(string); i++) {
|
||||
if(string[i] >= 'A' && string[i] <= 'Z') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void make_lowercase(char *string)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < strlen(string); i++) {
|
||||
if(string[i] >= 'A' && string[i] <= 'Z') {
|
||||
string[i] = (string[i] - 'A') + 'a';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Node *
|
||||
ParseFunc(ParseState *pstate, char *funcname, List *fargs, int *curr_resno)
|
||||
{
|
||||
@ -1987,6 +2014,27 @@ ParseFunc(ParseState *pstate, char *funcname, List *fargs, int *curr_resno)
|
||||
|
||||
AddAggToParseState(pstate, aggreg);
|
||||
return (Node*)aggreg;
|
||||
} else {
|
||||
/* try one more time with lowercase --djm 8/17/96 */
|
||||
if(!is_lowercase(funcname)) {
|
||||
char *lowercase_funcname = strdup(funcname);
|
||||
|
||||
make_lowercase(lowercase_funcname);
|
||||
if (strcmp(lowercase_funcname, "count") == 0)
|
||||
basetype = 0;
|
||||
else
|
||||
basetype = exprType(lfirst(fargs));
|
||||
if (SearchSysCacheTuple(AGGNAME,
|
||||
PointerGetDatum(lowercase_funcname),
|
||||
ObjectIdGetDatum(basetype),
|
||||
0, 0)) {
|
||||
Aggreg *aggreg = ParseAgg(lowercase_funcname,
|
||||
basetype, lfirst(fargs));
|
||||
|
||||
AddAggToParseState(pstate, aggreg);
|
||||
return (Node*)aggreg;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/catalog_utils.c,v 1.9 1996/11/10 03:01:23 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/catalog_utils.c,v 1.10 1996/11/13 20:48:58 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -108,6 +108,9 @@ static Oid **argtype_inherit(int nargs, Oid *oid_array);
|
||||
static Oid **genxprod(InhPaths *arginh, int nargs);
|
||||
static int findsupers(Oid relid, Oid **supervec);
|
||||
|
||||
static bool is_lowercase(char *string);
|
||||
static void make_lowercase(char *string);
|
||||
|
||||
/* check to see if a type id is valid,
|
||||
* returns true if it is. By using this call before calling
|
||||
* get_id_type or get_id_typname, more meaningful error messages
|
||||
@ -1010,6 +1013,30 @@ func_select_candidate(int nargs,
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static bool is_lowercase(char *string)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < strlen(string); i++) {
|
||||
if(string[i] >= 'A' && string[i] <= 'Z') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void make_lowercase(char *string)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < strlen(string); i++) {
|
||||
if(string[i] >= 'A' && string[i] <= 'Z') {
|
||||
string[i] = (string[i] - 'A') + 'a';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
func_get_detail(char *funcname,
|
||||
int nargs,
|
||||
@ -1105,6 +1132,24 @@ func_get_detail(char *funcname,
|
||||
if (!HeapTupleIsValid(ftup)) {
|
||||
Type tp;
|
||||
|
||||
/*
|
||||
* everything else has failed--try converting the function
|
||||
* name to lowercase, and do everything one more time
|
||||
* (if it's not already lowercase). so ODBC applications
|
||||
* that expect uppercase names to work can work. --djm 8/17/96
|
||||
*/
|
||||
if(!is_lowercase(funcname)) {
|
||||
char *lowercase_funcname = strdup(funcname);
|
||||
bool result;
|
||||
|
||||
make_lowercase(lowercase_funcname);
|
||||
result = func_get_detail(lowercase_funcname, nargs, oid_array,
|
||||
funcid, rettype, retset,
|
||||
true_typeids);
|
||||
|
||||
free(lowercase_funcname);
|
||||
return result;
|
||||
} else {
|
||||
if (nargs == 1) {
|
||||
tp = get_id_type(oid_array[0]);
|
||||
if (typetypetype(tp) == 'c')
|
||||
@ -1112,6 +1157,7 @@ func_get_detail(char *funcname,
|
||||
funcname);
|
||||
}
|
||||
func_error("func_get_detail", funcname, nargs, (int*)oid_array);
|
||||
}
|
||||
} else {
|
||||
pform = (Form_pg_proc) GETSTRUCT(ftup);
|
||||
*funcid = ftup->t_oid;
|
||||
|
@ -10,7 +10,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.15 1996/11/11 12:14:09 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.16 1996/11/13 20:49:00 scrappy Exp $
|
||||
*
|
||||
* HISTORY
|
||||
* AUTHOR DATE MAJOR EVENT
|
||||
@ -114,7 +114,7 @@ static Node *makeA_Expr(int op, char *opname, Node *lexpr, Node *rexpr);
|
||||
class, index_name, var_name, name, file_name, recipe_name
|
||||
|
||||
%type <str> opt_id, opt_portal_name,
|
||||
before_clause, after_clause, all_Op, MathOp, opt_name, opt_unique
|
||||
before_clause, after_clause, all_Op, MathOp, opt_name, opt_unique,
|
||||
result, OptUseOp, opt_class, opt_range_start, opt_range_end,
|
||||
SpecialRuleRelation
|
||||
|
||||
@ -123,14 +123,14 @@ static Node *makeA_Expr(int op, char *opname, Node *lexpr, Node *rexpr);
|
||||
|
||||
%type <list> queryblock, relation_name_list, OptTableElementList,
|
||||
tableElementList, OptInherit, definition,
|
||||
opt_with_func, def_args, def_name_list, func_argtypes,
|
||||
opt_with, def_args, def_name_list, func_argtypes,
|
||||
oper_argtypes, OptStmtList, OptStmtBlock, opt_column_list, columnList,
|
||||
sort_clause, sortby_list, index_params,
|
||||
name_list, from_clause, from_list, opt_array_bounds, nest_array_bounds,
|
||||
expr_list, attrs, res_target_list, res_target_list2, def_list,
|
||||
opt_indirection, group_clause, groupby_list, explain_options
|
||||
|
||||
%type <boolean> opt_inh_star, opt_binary, opt_instead, opt_with_copy
|
||||
%type <boolean> opt_inh_star, opt_binary, opt_instead, opt_with_copy, index_opt_unique
|
||||
|
||||
%type <ival> copy_dirn, archive_type, OptArchiveType, OptArchiveLocation,
|
||||
def_type, opt_direction, remove_type, opt_column, event
|
||||
@ -658,17 +658,18 @@ opt_portal_name: IN name { $$ = $2;}
|
||||
* [where <qual>] is not supported anymore
|
||||
*****************************************************************************/
|
||||
|
||||
IndexStmt: CREATE INDEX index_name ON relation_name
|
||||
access_method_clause '(' index_params ')' opt_with_func
|
||||
IndexStmt: CREATE index_opt_unique INDEX index_name ON relation_name
|
||||
access_method_clause '(' index_params ')' opt_with
|
||||
{
|
||||
/* should check that access_method is valid,
|
||||
etc ... but doesn't */
|
||||
IndexStmt *n = makeNode(IndexStmt);
|
||||
n->idxname = $3;
|
||||
n->relname = $5;
|
||||
n->accessMethod = $6;
|
||||
n->indexParams = $8;
|
||||
n->withClause = $10;
|
||||
n->unique = $2;
|
||||
n->idxname = $4;
|
||||
n->relname = $6;
|
||||
n->accessMethod = $7;
|
||||
n->indexParams = $9;
|
||||
n->withClause = $11;
|
||||
n->whereClause = NULL;
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
@ -677,6 +678,11 @@ IndexStmt: CREATE INDEX index_name ON relation_name
|
||||
access_method_clause: USING access_method { $$ = $2; }
|
||||
| /* empty -- 'btree' is default access method */
|
||||
{ $$ = "btree"; }
|
||||
;
|
||||
|
||||
index_opt_unique: UNIQUE { $$ = TRUE; }
|
||||
| /*empty*/ { $$ = FALSE; }
|
||||
;
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
@ -731,7 +737,7 @@ RecipeStmt: EXECUTE RECIPE recipe_name
|
||||
*****************************************************************************/
|
||||
|
||||
ProcedureStmt: CREATE FUNCTION def_name def_args
|
||||
RETURNS def_arg opt_with_func AS Sconst LANGUAGE Sconst
|
||||
RETURNS def_arg opt_with AS Sconst LANGUAGE Sconst
|
||||
{
|
||||
ProcedureStmt *n = makeNode(ProcedureStmt);
|
||||
n->funcname = $3;
|
||||
@ -743,7 +749,7 @@ ProcedureStmt: CREATE FUNCTION def_name def_args
|
||||
$$ = (Node *)n;
|
||||
};
|
||||
|
||||
opt_with_func: WITH definition { $$ = $2; }
|
||||
opt_with: WITH definition { $$ = $2; }
|
||||
| /* EMPTY */ { $$ = NIL; }
|
||||
;
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.3 1996/08/24 20:48:46 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.4 1996/11/13 20:49:04 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -130,6 +130,7 @@ static ScanKeyword ScanKeywords[] = {
|
||||
{ "to", TO },
|
||||
{ "transaction", TRANSACTION },
|
||||
{ "type", P_TYPE },
|
||||
{ "unique", UNIQUE },
|
||||
{ "update", UPDATE },
|
||||
{ "using", USING },
|
||||
{ "vacuum", VACUUM },
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/parse_query.c,v 1.7 1996/11/08 00:56:17 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/parse_query.c,v 1.8 1996/11/13 20:49:05 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -651,7 +651,9 @@ make_const(Value *value)
|
||||
elog(NOTICE,"unknown type : %d\n", nodeTag(value));
|
||||
|
||||
/* null const */
|
||||
con = makeConst(0, 0, (Datum)NULL, TRUE, 0, FALSE);
|
||||
/* if we don't set a type here, things will break. */
|
||||
/* so set it to type 'unknown'. */
|
||||
con = makeConst(UNKNOWNOID, 0, (Datum)NULL, TRUE, 0, FALSE);
|
||||
return con;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.10 1996/11/10 03:30:46 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.11 1996/11/13 20:49:07 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -216,36 +216,36 @@ parser_typecast(Value *expr, TypeName *typename, int typlen)
|
||||
|
||||
#if 0 /* fix me */
|
||||
switch ( CInteger(lfirst(expr)) ) {
|
||||
case 23: /* int4 */
|
||||
case INT4OID: /* int4 */
|
||||
const_string = (char *) palloc(256);
|
||||
string_palloced = true;
|
||||
sprintf(const_string,"%d", ((Const*)lnext(expr))->constvalue);
|
||||
break;
|
||||
|
||||
case 19: /* char16 */
|
||||
case NAMEOID: /* char16 */
|
||||
const_string = (char *) palloc(256);
|
||||
string_palloced = true;
|
||||
sprintf(const_string,"%s", ((Const*)lnext(expr))->constvalue);
|
||||
break;
|
||||
|
||||
case 18: /* char */
|
||||
case CHAROID: /* char */
|
||||
const_string = (char *) palloc(256);
|
||||
string_palloced = true;
|
||||
sprintf(const_string,"%c", ((Const)lnext(expr))->constvalue);
|
||||
break;
|
||||
|
||||
case 701:/* float8 */
|
||||
case FLOAT8OID:/* float8 */
|
||||
const_string = (char *) palloc(256);
|
||||
string_palloced = true;
|
||||
sprintf(const_string,"%f", ((Const)lnext(expr))->constvalue);
|
||||
break;
|
||||
|
||||
case 25: /* text */
|
||||
case TEXTOID: /* text */
|
||||
const_string = DatumGetPointer(((Const)lnext(expr))->constvalue);
|
||||
const_string = (char *) textout((struct varlena *)const_string);
|
||||
break;
|
||||
|
||||
case 705: /* unknown */
|
||||
case UNKNOWNOID: /* unknown */
|
||||
const_string = DatumGetPointer(((Const)lnext(expr))->constvalue);
|
||||
const_string = (char *) textout((struct varlena *)const_string);
|
||||
break;
|
||||
@ -312,25 +312,25 @@ parser_typecast2(Node *expr, int exprType, Type tp, int typlen)
|
||||
switch (exprType) {
|
||||
case 0: /* NULL */
|
||||
break;
|
||||
case 23: /* int4 */
|
||||
case INT4OID: /* int4 */
|
||||
const_string = (char *) palloc(256);
|
||||
string_palloced = true;
|
||||
sprintf(const_string,"%d",
|
||||
(int) ((Const*)expr)->constvalue);
|
||||
break;
|
||||
case 19: /* char16 */
|
||||
case NAMEOID: /* char16 */
|
||||
const_string = (char *) palloc(256);
|
||||
string_palloced = true;
|
||||
sprintf(const_string,"%s",
|
||||
(char*) ((Const*)expr)->constvalue);
|
||||
break;
|
||||
case 18: /* char */
|
||||
case CHAROID: /* char */
|
||||
const_string = (char *) palloc(256);
|
||||
string_palloced = true;
|
||||
sprintf(const_string,"%c",
|
||||
(char) ((Const*)expr)->constvalue);
|
||||
break;
|
||||
case 700: /* float4 */
|
||||
case FLOAT4OID: /* float4 */
|
||||
{
|
||||
float32 floatVal =
|
||||
DatumGetFloat32(((Const*)expr)->constvalue);
|
||||
@ -339,7 +339,7 @@ parser_typecast2(Node *expr, int exprType, Type tp, int typlen)
|
||||
sprintf(const_string,"%f", *floatVal);
|
||||
break;
|
||||
}
|
||||
case 701:/* float8 */
|
||||
case FLOAT8OID:/* float8 */
|
||||
{
|
||||
float64 floatVal =
|
||||
DatumGetFloat64(((Const*)expr)->constvalue);
|
||||
@ -348,12 +348,12 @@ parser_typecast2(Node *expr, int exprType, Type tp, int typlen)
|
||||
sprintf(const_string,"%f", *floatVal);
|
||||
break;
|
||||
}
|
||||
case 25: /* text */
|
||||
case TEXTOID: /* text */
|
||||
const_string =
|
||||
DatumGetPointer(((Const*)expr)->constvalue );
|
||||
const_string = (char *) textout((struct varlena *)const_string);
|
||||
break;
|
||||
case 705: /* unknown */
|
||||
case UNKNOWNOID: /* unknown */
|
||||
const_string =
|
||||
DatumGetPointer(((Const*)expr)->constvalue );
|
||||
const_string = (char *) textout((struct varlena *)const_string);
|
||||
|
Reference in New Issue
Block a user