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
53c4f123
Commit
53c4f123
authored
Jun 25, 2003
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UPDATE ... SET <col> = DEFAULT
Rod Taylor
parent
a09ccc70
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
90 additions
and
49 deletions
+90
-49
doc/src/sgml/ref/update.sgml
doc/src/sgml/ref/update.sgml
+11
-2
src/backend/nodes/copyfuncs.c
src/backend/nodes/copyfuncs.c
+6
-6
src/backend/nodes/equalfuncs.c
src/backend/nodes/equalfuncs.c
+4
-4
src/backend/parser/analyze.c
src/backend/parser/analyze.c
+6
-18
src/backend/parser/gram.y
src/backend/parser/gram.y
+11
-2
src/backend/parser/parse_target.c
src/backend/parser/parse_target.c
+27
-10
src/backend/rewrite/rewriteHandler.c
src/backend/rewrite/rewriteHandler.c
+20
-2
src/include/nodes/nodes.h
src/include/nodes/nodes.h
+2
-2
src/include/nodes/parsenodes.h
src/include/nodes/parsenodes.h
+3
-3
No files found.
doc/src/sgml/ref/update.sgml
View file @
53c4f123
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/update.sgml,v 1.2
1 2003/04/26 23:56:51 petere
Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/update.sgml,v 1.2
2 2003/06/25 04:19:24 momjian
Exp $
PostgreSQL documentation
-->
...
...
@@ -16,7 +16,7 @@ PostgreSQL documentation
<refsynopsisdiv>
<synopsis>
UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replaceable class="PARAMETER">column</replaceable> =
<replaceable class="PARAMETER">expression</replaceable>
[, ...]
UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replaceable class="PARAMETER">column</replaceable> =
{ <replaceable class="PARAMETER">expression</replaceable> | DEFAULT }
[, ...]
[ FROM <replaceable class="PARAMETER">fromlist</replaceable> ]
[ WHERE <replaceable class="PARAMETER">condition</replaceable> ]
</synopsis>
...
...
@@ -77,6 +77,15 @@ UPDATE [ ONLY ] <replaceable class="PARAMETER">table</replaceable> SET <replacea
</listitem>
</varlistentry>
<varlistentry>
<term><literal>DEFAULT</literal></term>
<listitem>
<para>
This column will be filled with its default value.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">fromlist</replaceable></term>
<listitem>
...
...
src/backend/nodes/copyfuncs.c
View file @
53c4f123
...
...
@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.25
4 2003/06/25 03:40:17
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.25
5 2003/06/25 04:19:24
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -1661,10 +1661,10 @@ _copyFuncWithArgs(FuncWithArgs *from)
return
newnode
;
}
static
Insert
Default
*
_copy
InsertDefault
(
Insert
Default
*
from
)
static
SetTo
Default
*
_copy
SetToDefault
(
SetTo
Default
*
from
)
{
InsertDefault
*
newnode
=
makeNode
(
Insert
Default
);
SetToDefault
*
newnode
=
makeNode
(
SetTo
Default
);
return
newnode
;
}
...
...
@@ -2942,8 +2942,8 @@ copyObject(void *from)
case
T_FuncWithArgs
:
retval
=
_copyFuncWithArgs
(
from
);
break
;
case
T_
Insert
Default
:
retval
=
_copy
Insert
Default
(
from
);
case
T_
SetTo
Default
:
retval
=
_copy
SetTo
Default
(
from
);
break
;
default:
...
...
src/backend/nodes/equalfuncs.c
View file @
53c4f123
...
...
@@ -18,7 +18,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.19
7 2003/06/25 03:40:17
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.19
8 2003/06/25 04:19:24
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -728,7 +728,7 @@ _equalFuncWithArgs(FuncWithArgs *a, FuncWithArgs *b)
}
static
bool
_equal
InsertDefault
(
InsertDefault
*
a
,
Insert
Default
*
b
)
_equal
SetToDefault
(
SetToDefault
*
a
,
SetTo
Default
*
b
)
{
return
true
;
}
...
...
@@ -2055,8 +2055,8 @@ equal(void *a, void *b)
case
T_FuncWithArgs
:
retval
=
_equalFuncWithArgs
(
a
,
b
);
break
;
case
T_
Insert
Default
:
retval
=
_equal
Insert
Default
(
a
,
b
);
case
T_
SetTo
Default
:
retval
=
_equal
SetTo
Default
(
a
,
b
);
break
;
default:
...
...
src/backend/parser/analyze.c
View file @
53c4f123
...
...
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.27
6 2003/06/25 03:40:17
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.27
7 2003/06/25 04:19:24
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -660,23 +660,9 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt,
col
=
(
ResTarget
*
)
lfirst
(
icolumns
);
Assert
(
IsA
(
col
,
ResTarget
));
/*
* When the value is to be set to the column default we can simply
* drop the TLE now and handle it later on using methods for missing
* columns.
*/
if
(
IsA
(
tle
,
InsertDefault
))
{
qry
->
targetList
=
lremove
(
tle
,
qry
->
targetList
);
/* Note: the stmt->cols list is not adjusted to match */
}
else
{
/* Normal case */
Assert
(
!
tle
->
resdom
->
resjunk
);
updateTargetListEntry
(
pstate
,
tle
,
col
->
name
,
lfirsti
(
attnos
),
col
->
indirection
);
}
Assert
(
!
tle
->
resdom
->
resjunk
);
updateTargetListEntry
(
pstate
,
tle
,
col
->
name
,
lfirsti
(
attnos
),
col
->
indirection
);
icolumns
=
lnext
(
icolumns
);
attnos
=
lnext
(
attnos
);
...
...
@@ -2431,10 +2417,12 @@ transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt)
if
(
origTargetList
==
NIL
)
elog
(
ERROR
,
"UPDATE target count mismatch --- internal error"
);
origTarget
=
(
ResTarget
*
)
lfirst
(
origTargetList
);
updateTargetListEntry
(
pstate
,
tle
,
origTarget
->
name
,
attnameAttNum
(
pstate
->
p_target_relation
,
origTarget
->
name
,
true
),
origTarget
->
indirection
);
origTargetList
=
lnext
(
origTargetList
);
}
if
(
origTargetList
!=
NIL
)
...
...
src/backend/parser/gram.y
View file @
53c4f123
...
...
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.4
19 2003/06/25 03:40:18
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.4
20 2003/06/25 04:19:24
momjian Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
...
...
@@ -6945,6 +6945,15 @@ update_target_el:
$$->indirection = $2;
$$->val = (Node *)$4;
}
| ColId opt_indirection '=' DEFAULT
{
SetToDefault *def = makeNode(SetToDefault);
$$ = makeNode(ResTarget);
$$->name = $1;
$$->indirection = NULL;
$$->val = (Node *)def;
}
;
insert_target_list:
...
...
@@ -6956,7 +6965,7 @@ insert_target_el:
target_el { $$ = $1; }
| DEFAULT
{
InsertDefault *def = makeNode(Insert
Default);
SetToDefault *def = makeNode(SetTo
Default);
$$ = makeNode(ResTarget);
$$->name = NULL;
$$->indirection = NULL;
...
...
src/backend/parser/parse_target.c
View file @
53c4f123
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.10
2 2003/05/31 19:03:34 tgl
Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.10
3 2003/06/25 04:19:24 momjian
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -177,19 +177,24 @@ transformTargetList(ParseState *pstate, List *targetlist)
false
));
}
}
else
if
(
IsA
(
res
->
val
,
Insert
Default
))
else
if
(
IsA
(
res
->
val
,
SetTo
Default
))
{
InsertDefault
*
newnode
=
makeNode
(
InsertDefault
);
/*
* If this is a DEFAULT element, we make a junk entry which
* will get dropped on return to transformInsertStmt().
* If this is a DEFAULT element, we make a standard entry using
* the default for the target expression. rewriteTargetList will
* substitute the columns default for this expression.
*/
p_target
=
lappend
(
p_target
,
newnode
);
p_target
=
lappend
(
p_target
,
makeTargetEntry
(
makeResdom
((
AttrNumber
)
pstate
->
p_next_resno
++
,
UNKNOWNOID
,
-
1
,
res
->
name
,
false
),
(
Expr
*
)
res
->
val
));
}
else
{
/* Everything else but ColumnRef and
Insert
Default */
/* Everything else but ColumnRef and
SetTo
Default */
p_target
=
lappend
(
p_target
,
transformTargetEntry
(
pstate
,
res
->
val
,
...
...
@@ -321,9 +326,10 @@ updateTargetListEntry(ParseState *pstate,
int
attrno
,
List
*
indirection
)
{
Oid
type_id
=
exprType
((
Node
*
)
tle
->
expr
);
/* type of value provided */
Oid
type_id
;
/* type of value provided */
Oid
attrtype
;
/* type of target column */
int32
attrtypmod
;
bool
isDefault
=
false
;
Resdom
*
resnode
=
tle
->
resdom
;
Relation
rd
=
pstate
->
p_target_relation
;
...
...
@@ -333,6 +339,17 @@ updateTargetListEntry(ParseState *pstate,
attrtype
=
attnumTypeId
(
rd
,
attrno
);
attrtypmod
=
rd
->
rd_att
->
attrs
[
attrno
-
1
]
->
atttypmod
;
/* The type of the default column is equivalent to that of the column */
if
(
tle
->
expr
!=
NULL
&&
IsA
(
tle
->
expr
,
SetToDefault
))
{
type_id
=
attrtype
;
isDefault
=
true
;
}
/* Otherwise the expression holds the type */
else
type_id
=
exprType
((
Node
*
)
tle
->
expr
);
/*
* If there are subscripts on the target column, prepare an array
* assignment expression. This will generate an array value that the
...
...
@@ -383,7 +400,7 @@ updateTargetListEntry(ParseState *pstate,
* coercion. But accept InvalidOid, which indicates the source is
* a NULL constant. (XXX is that still true?)
*/
if
(
type_id
!=
InvalidOid
)
if
(
!
isDefault
&&
type_id
!=
InvalidOid
)
{
tle
->
expr
=
(
Expr
*
)
coerce_to_target_type
(
pstate
,
...
...
src/backend/rewrite/rewriteHandler.c
View file @
53c4f123
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.12
0 2003/05/02 20:54:35 tgl
Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.12
1 2003/06/25 04:19:24 momjian
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -307,7 +307,25 @@ rewriteTargetList(Query *parsetree, Relation target_relation)
{
Assert
(
strcmp
(
resdom
->
resname
,
NameStr
(
att_tup
->
attname
))
==
0
);
new_tle
=
process_matched_tle
(
old_tle
,
new_tle
);
if
(
old_tle
->
expr
!=
NULL
&&
IsA
(
old_tle
->
expr
,
SetToDefault
))
{
/* Set to the default value of the column, as requested */
Node
*
new_expr
;
new_expr
=
build_column_default
(
target_relation
,
attrno
);
new_tle
=
makeTargetEntry
(
makeResdom
(
attrno
,
att_tup
->
atttypid
,
att_tup
->
atttypmod
,
pstrdup
(
NameStr
(
att_tup
->
attname
)),
false
),
(
Expr
*
)
new_expr
);
}
else
/* Normal Case */
new_tle
=
process_matched_tle
(
old_tle
,
new_tle
);
/* keep scanning to detect multiple assignments to attr */
}
}
...
...
src/include/nodes/nodes.h
View file @
53c4f123
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: nodes.h,v 1.14
1 2003/06/25 03:40:19
momjian Exp $
* $Id: nodes.h,v 1.14
2 2003/06/25 04:19:24
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -277,7 +277,7 @@ typedef enum NodeTag
T_PrivGrantee
,
T_FuncWithArgs
,
T_PrivTarget
,
T_
Insert
Default
,
T_
SetTo
Default
,
T_CreateOpClassItem
,
T_CompositeTypeStmt
,
T_InhRelation
,
...
...
src/include/nodes/parsenodes.h
View file @
53c4f123
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: parsenodes.h,v 1.2
39 2003/06/25 03:40:19
momjian Exp $
* $Id: parsenodes.h,v 1.2
40 2003/06/25 04:19:24
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -279,10 +279,10 @@ typedef struct ResTarget
/*
* Empty node used as a marker for Default Columns
*/
typedef
struct
Insert
Default
typedef
struct
SetTo
Default
{
NodeTag
type
;
}
Insert
Default
;
}
SetTo
Default
;
/*
* SortGroupBy - for ORDER BY clause
...
...
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