Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
d7050cb6
Commit
d7050cb6
authored
Mar 31, 1998
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge rename name page into alter table. Fix UNION with DISTINCT
or ORDER BY bug.
parent
62943bb7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
134 additions
and
89 deletions
+134
-89
src/backend/optimizer/prep/prepunion.c
src/backend/optimizer/prep/prepunion.c
+23
-14
src/backend/parser/parse_clause.c
src/backend/parser/parse_clause.c
+8
-2
src/man/alter_table.l
src/man/alter_table.l
+49
-10
src/man/rename.l
src/man/rename.l
+0
-63
src/test/regress/sql/name.sql
src/test/regress/sql/name.sql
+54
-0
No files found.
src/backend/optimizer/prep/prepunion.c
View file @
d7050cb6
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.2
1 1998/03/30 19:04:41
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.2
2 1998/03/31 04:43:49
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -64,12 +64,13 @@ plan_union_queries(Query *parse)
{
List
*
union_plans
=
NIL
,
*
ulist
,
*
unionall_queries
,
*
union
_
all_queries
,
*
union_rts
,
*
last_union
=
NIL
;
*
last_union
=
NIL
,
*
hold_sortClause
=
parse
->
sortClause
;
bool
union_all_found
=
false
,
union_found
=
false
,
last_unionall_flag
=
false
;
last_union
_
all_flag
=
false
;
/*------------------------------------------------------------------
*
...
...
@@ -120,17 +121,25 @@ plan_union_queries(Query *parse)
union_found
=
true
;
last_union
=
ulist
;
}
last_unionall_flag
=
union_query
->
unionall
;
last_union
_
all_flag
=
union_query
->
unionall
;
}
/* Is this a simple one */
if
(
!
union_all_found
||
!
union_found
||
/* A trailing UNION negates the affect of earlier UNION ALLs */
!
last_unionall_flag
)
!
last_union
_
all_flag
)
{
List
*
hold_unionClause
=
parse
->
unionClause
;
/* we will do this later, so don't do it now */
if
(
!
union_all_found
||
!
last_union_all_flag
)
{
parse
->
sortClause
=
NIL
;
parse
->
uniqueFlag
=
NULL
;
}
parse
->
unionClause
=
NIL
;
/* prevent recursion */
union_plans
=
lcons
(
union_planner
(
parse
),
NIL
);
union_rts
=
lcons
(
parse
->
rtable
,
NIL
);
...
...
@@ -154,7 +163,7 @@ plan_union_queries(Query *parse)
*/
/* save off everthing past the last UNION */
unionall_queries
=
lnext
(
last_union
);
union
_
all_queries
=
lnext
(
last_union
);
/* clip off the list to remove the trailing UNION ALLs */
lnext
(
last_union
)
=
NIL
;
...
...
@@ -167,21 +176,21 @@ plan_union_queries(Query *parse)
union_rts
=
lcons
(
parse
->
rtable
,
NIL
);
/* Append the remainging UNION ALLs */
foreach
(
ulist
,
unionall_queries
)
foreach
(
ulist
,
union
_
all_queries
)
{
Query
*
unionall_query
=
lfirst
(
ulist
);
Query
*
union
_
all_query
=
lfirst
(
ulist
);
union_plans
=
lappend
(
union_plans
,
union_planner
(
unionall_query
));
union_rts
=
lappend
(
union_rts
,
unionall_query
->
rtable
);
union_plans
=
lappend
(
union_plans
,
union_planner
(
union
_
all_query
));
union_rts
=
lappend
(
union_rts
,
union
_
all_query
->
rtable
);
}
}
/* We have already split UNION and UNION ALL and we made it consistent */
if
(
!
last_unionall_flag
)
if
(
!
last_union
_
all_flag
)
{
parse
->
uniqueFlag
=
"*"
;
parse
->
sortClause
=
transformSortClause
(
NULL
,
NIL
,
parse
->
sortClause
,
hold_
sortClause
,
parse
->
targetList
,
"*"
);
}
else
...
...
@@ -195,7 +204,7 @@ plan_union_queries(Query *parse)
union_rts
,
0
,
NULL
,
((
Plan
*
)
lfirst
(
union_plans
))
->
targetl
ist
));
parse
->
targetL
ist
));
}
...
...
src/backend/parser/parse_clause.c
View file @
d7050cb6
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.1
4 1998/03/18 15:47:51
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.1
5 1998/03/31 04:43:53
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -313,7 +313,13 @@ transformSortClause(ParseState *pstate,
{
SortClause
*
sortcl
=
lfirst
(
s
);
if
(
sortcl
->
resdom
==
tlelt
->
resdom
)
/*
* We use equal() here because we are called for UNION
* from the optimizer, and at that point, the sort clause
* resdom pointers don't match the target list resdom
* pointers
*/
if
(
equal
(
sortcl
->
resdom
,
tlelt
->
resdom
))
break
;
s
=
lnext
(
s
);
}
...
...
src/man/alter_table.l
View file @
d7050cb6
.\" This is -*-nroff-*-
.\" XXX standard disclaimer belongs here....
.\" $Header: /cvsroot/pgsql/src/man/Attic/alter_table.l,v 1.
4 1998/01/11 22:17:04
momjian Exp $
.\" $Header: /cvsroot/pgsql/src/man/Attic/alter_table.l,v 1.
5 1998/03/31 04:44:19
momjian Exp $
.TH "ALTER TABLE" SQL 09/25/97 PostgreSQL
.SH NAME
alter table - add attributes to a class
alter table - add attributes to a class
, or rename an attribute or class
.SH SYNOPSIS
.nf
\fBalter table\fR classname [ * ]
\fBadd\fR [ \fBcolumn\fR ] attname type
.fi
.nf
\fBalter table\fR classname [ * ]
\fBadd\fR \fB(\fR attname type \fB)\fR
\fBalter table\fR classname1
\fBrename to\fR classname2
\fBalter table\fR classname1 [\fB*\fR]
\fBrename [column]\fR attname1 \fBto\fR attname2
.fi
.SH DESCRIPTION
The
.BR "alter table"
command
causes a new attribute to be added to an existing class,
.IR classname .
command causes a new attribute to be added to an existing class,
.IR classname ,
or the name of a class or attribute to change
without changing any of the data contained in the affected class.
Thus, the class or attribute will remain of the same type and size
after this command is executed.
.PP
The new attributes and their types are specified
in the same style and with the the same restrictions as in
.IR "create table" (l).
...
...
@@ -33,7 +41,9 @@ attribute will not be added to any of the subclasses.) This should
be done when adding an attribute to a superclass. If it is not,
queries on the inheritance hierarchy such as
.nf
select * from super* s
select * from super* s
.fi
will not work because the subclasses will be missing an attribute
found in the superclass.
...
...
@@ -45,6 +55,24 @@ desired, a subsequent
.IR update (l)
query should be run.
.PP
In order to rename an attribute in each class in an entire inheritance
hierarchy, use the
.IR classname
of the superclass and append a \*(lq*\*(rq. (By default, the attribute
will not be renamed in any of the subclasses.) This should
.BR always
be done when changing an attribute name in a superclass. If it is
not, queries on the inheritance hierarchy such as
.nf
select * from super* s
.fi
will not work because the subclasses will be (in effect) missing an
attribute found in the superclass.
.PP
You must own the class being modified in order to rename it or part of
its schema. Renaming any part of the schema of a system catalog is
not permitted.
.PP
You must own the class in order to change its schema.
.SH EXAMPLE
.nf
...
...
@@ -52,14 +80,25 @@ You must own the class in order to change its schema.
-- add the date of hire to the emp class
--
alter table emp add column hiredate abstime
.fi
.nf
--
-- add a health-care number to all persons
-- (including employees, students, ...)
--
alter table person * add column health_care_id int4
--
-- change the emp class to personnel
--
alter table emp rename to personnel
--
-- change the sports attribute to hobbies
--
alter table emp rename column sports to hobbies
--
-- make a change to an inherited attribute
--
alter table person * rename column last_name to family_name
.fi
.SH "SEE ALSO"
create table (l),
update (l).
src/man/rename.l
deleted
100644 → 0
View file @
62943bb7
.\" This is -*-nroff-*-
.\" XXX standard disclaimer belongs here....
.\" $Header: /cvsroot/pgsql/src/man/Attic/rename.l,v 1.3 1998/01/11 22:17:55 momjian Exp $
.TH RENAME SQL 02/08/94 PostgreSQL PostgreSQL
.SH NAME
rename - rename a class or an attribute in a class
.SH SYNOPSIS
.nf
\fBalter table\fR classname1
\fBrename to\fR classname2
\fBalter table\fR classname1 [\fB*\fR]
\fBrename [column]\fR attname1 \fBto\fR attname2
.fi
.SH DESCRIPTION
The
.BR rename
command
causes the name of a class or attribute to change without changing any
of the data contained in the affected class. Thus, the class or
attribute will remain of the same type and size after this command is
executed.
.PP
In order to rename an attribute in each class in an entire inheritance
hierarchy, use the
.IR classname
of the superclass and append a \*(lq*\*(rq. (By default, the attribute
will not be renamed in any of the subclasses.) This should
.BR always
be done when changing an attribute name in a superclass. If it is
not, queries on the inheritance hierarchy such as
.nf
select * from super* s
.fi
will not work because the subclasses will be (in effect) missing an
attribute found in the superclass.
.PP
You must own the class being modified in order to rename it or part of
its schema. Renaming any part of the schema of a system catalog is
not permitted.
.SH EXAMPLE
.nf
--
-- change the emp class to personnel
--
alter table emp rename to personnel
.fi
.nf
--
-- change the sports attribute to hobbies
--
alter table emp rename column sports to hobbies
.fi
.nf
--
-- make a change to an inherited attribute
--
alter table person * rename column last_name to family_name
.fi
.SH BUGS
Execution of historical queries using classes and attributes whose
names have changed will produce incorrect results in many situations.
.PP
Renaming of types, operators, rules, etc., should also be supported.
src/test/regress/sql/name.sql
0 → 100644
View file @
d7050cb6
--**************** testing built-in type name **************
--
-- all inputs are silently truncated at NAMEDATALEN (32) characters
--
-- fixed-length by reference
SELECT
'name string'
::
name
=
'name string'
::
name
AS
"True"
;
SELECT
'name string'
::
name
=
'name string '
::
name
AS
"False"
;
--
--
--
CREATE
TABLE
NAME_TBL
(
f1
name
);
INSERT
INTO
NAME_TBL
(
f1
)
VALUES
(
'ABCDEFGHIJKLMNOP'
);
INSERT
INTO
NAME_TBL
(
f1
)
VALUES
(
'abcdefghijklmnop'
);
INSERT
INTO
NAME_TBL
(
f1
)
VALUES
(
'asdfghjkl;'
);
INSERT
INTO
NAME_TBL
(
f1
)
VALUES
(
'343f%2a'
);
INSERT
INTO
NAME_TBL
(
f1
)
VALUES
(
'd34aaasdf'
);
INSERT
INTO
NAME_TBL
(
f1
)
VALUES
(
''
);
INSERT
INTO
NAME_TBL
(
f1
)
VALUES
(
'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'
);
SELECT
''
AS
seven
,
NAME_TBL
.
*
;
SELECT
''
AS
six
,
c
.
f1
FROM
NAME_TBL
c
WHERE
c
.
f1
<>
'ABCDEFGHIJKLMNOP'
;
SELECT
''
AS
one
,
c
.
f1
FROM
NAME_TBL
c
WHERE
c
.
f1
=
'ABCDEFGHIJKLMNOP'
;
SELECT
''
AS
three
,
c
.
f1
FROM
NAME_TBL
c
WHERE
c
.
f1
<
'ABCDEFGHIJKLMNOP'
;
SELECT
''
AS
four
,
c
.
f1
FROM
NAME_TBL
c
WHERE
c
.
f1
<=
'ABCDEFGHIJKLMNOP'
;
SELECT
''
AS
three
,
c
.
f1
FROM
NAME_TBL
c
WHERE
c
.
f1
>
'ABCDEFGHIJKLMNOP'
;
SELECT
''
AS
four
,
c
.
f1
FROM
NAME_TBL
c
WHERE
c
.
f1
>=
'ABCDEFGHIJKLMNOP'
;
SELECT
''
AS
seven
,
c
.
f1
FROM
NAME_TBL
c
WHERE
c
.
f1
~
'.*'
;
SELECT
''
AS
zero
,
c
.
f1
FROM
NAME_TBL
c
WHERE
c
.
f1
!~
'.*'
;
SELECT
''
AS
three
,
c
.
f1
FROM
NAME_TBL
c
WHERE
c
.
f1
~
'[0-9]'
;
SELECT
''
AS
two
,
c
.
f1
FROM
NAME_TBL
c
WHERE
c
.
f1
~
'.*asdf.*'
;
DROP
TABLE
NAME_TBL
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment