diff -durpN pgsql.orig/doc/src/sgml/catalogs.sgml pgsql/doc/src/sgml/catalogs.sgml
--- pgsql.orig/doc/src/sgml/catalogs.sgml	2006-08-01 16:12:44.000000000 +0200
+++ pgsql/doc/src/sgml/catalogs.sgml	2006-08-09 17:20:19.000000000 +0200
@@ -920,6 +920,25 @@
       </entry>
      </row>
 
+     <row>
+      <entry><structfield>attidentity</structfield></entry>
+      <entry><type>bool</type></entry>
+      <entry></entry>
+      <entry>
+       This column is an IDENTITY column.
+      </entry>
+     </row>
+
+     <row>
+      <entry><structfield>attforceddef</structfield></entry>
+      <entry><type>bool</type></entry>
+      <entry></entry>
+      <entry>
+       This column is defined as GENERATED ALWAYS and the
+       default value is always enforced.
+      </entry>
+     </row>
+
     </tbody>
    </tgroup>
   </table>
diff -durpN pgsql.orig/doc/src/sgml/datatype.sgml pgsql/doc/src/sgml/datatype.sgml
--- pgsql.orig/doc/src/sgml/datatype.sgml	2006-07-11 16:09:31.000000000 +0200
+++ pgsql/doc/src/sgml/datatype.sgml	2006-08-09 17:20:19.000000000 +0200
@@ -697,25 +697,29 @@ NUMERIC
 <programlisting>
 CREATE TABLE <replaceable class="parameter">tablename</replaceable> (
     <replaceable class="parameter">colname</replaceable> SERIAL
+	[ GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( <replaceable>sequence_options</replaceable> ) ] ]
 );
 </programlisting>
 
      is equivalent to specifying:
 
 <programlisting>
-CREATE SEQUENCE <replaceable class="parameter">tablename</replaceable>_<replaceable class="parameter">colname</replaceable>_seq;
+CREATE SEQUENCE <replaceable class="parameter">tablename</replaceable>_<replaceable class="parameter">colname</replaceable>_seq
+	[ <replaceable>sequence_options</replaceable> ];
 CREATE TABLE <replaceable class="parameter">tablename</replaceable> (
     <replaceable class="parameter">colname</replaceable> integer DEFAULT nextval('<replaceable class="parameter">tablename</replaceable>_<replaceable class="parameter">colname</replaceable>_seq') NOT NULL
 );
 </programlisting>
 
      Thus, we have created an integer column and arranged for its default
-     values to be assigned from a sequence generator.  A <literal>NOT NULL</>
-     constraint is applied to ensure that a null value cannot be explicitly
-     inserted, either.  In most cases you would also want to attach a
-     <literal>UNIQUE</> or <literal>PRIMARY KEY</> constraint to prevent
-     duplicate values from being inserted by accident, but this is
-     not automatic.
+     values to be assigned from a sequence generator with the optional
+     <replaceable class="parameter">sequence_options</replaceable>.
+     For the options, look for the documentation of <programlisting>CREATE SEQUENCE</programlisting>.
+     A <literal>NOT NULL</> constraint is applied to ensure that
+     a null value cannot be explicitly inserted, either.
+     In most cases you would also want to attach a <literal>UNIQUE</> or
+     <literal>PRIMARY KEY</> constraint to prevent duplicate values
+     from being inserted by accident, but this is not automatic.
     </para>
 
     <note>
diff -durpN pgsql.orig/doc/src/sgml/ref/alter_table.sgml pgsql/doc/src/sgml/ref/alter_table.sgml
--- pgsql.orig/doc/src/sgml/ref/alter_table.sgml	2006-08-05 16:46:46.000000000 +0200
+++ pgsql/doc/src/sgml/ref/alter_table.sgml	2006-08-09 17:20:19.000000000 +0200
@@ -361,7 +361,9 @@ where <replaceable class="PARAMETER">act
      <para>
       The <literal>RENAME</literal> forms change the name of a table
       (or an index, sequence, or view) or the name of an individual column in
-      a table. There is no effect on the stored data.
+      a table. There is no effect on the stored data. If the column
+      is an IDENTITY column, the supporting sequence is also renamed
+      so it always tries to keep the <replaceable class="PARAMETER">tablename_columnname</replaceable>_seq form.
      </para>
     </listitem>
    </varlistentry>
@@ -664,7 +666,8 @@ ALTER TABLE table ALTER COLUMN anycol TY
     drop the default with <literal>DROP DEFAULT</>, perform the <literal>ALTER
     TYPE</>, and then use <literal>SET DEFAULT</> to add a suitable new
     default.  Similar considerations apply to indexes and constraints involving
-    the column.
+    the column. Note that both SET DEFAULT and DROP DEFAULT fail for
+    IDENTITY columns.
    </para>
 
    <para>
diff -durpN pgsql.orig/doc/src/sgml/ref/copy.sgml pgsql/doc/src/sgml/ref/copy.sgml
--- pgsql.orig/doc/src/sgml/ref/copy.sgml	2006-04-22 05:03:11.000000000 +0200
+++ pgsql/doc/src/sgml/ref/copy.sgml	2006-08-09 17:20:19.000000000 +0200
@@ -22,6 +22,7 @@ PostgreSQL documentation
  <refsynopsisdiv>
 <synopsis>
 COPY <replaceable class="parameter">tablename</replaceable> [ ( <replaceable class="parameter">column</replaceable> [, ...] ) ]
+    [ OVERRIDING { SYSTEM | USER } VALUE ]
     FROM { '<replaceable class="parameter">filename</replaceable>' | STDIN }
     [ [ WITH ] 
           [ BINARY ]
@@ -103,6 +104,17 @@ COPY <replaceable class="parameter">tabl
    </varlistentry>
 
    <varlistentry>
+    <term><literal>OVERRIDING { SYSTEM | USER } VALUE</literal></term>
+    <listitem>
+     <para>
+      Specifies that values override enforced default values
+      for GENERATED ALWAYS columns. Only effective for
+      <literal>COPY</literal> <replaceable class="parameter">tablename</replaceable> <literal>FROM</literal>.
+     </para>
+    </listitem>
+   </varlistentry>
+
+   <varlistentry>
     <term><replaceable class="parameter">filename</replaceable></term>
     <listitem>
      <para>
diff -durpN pgsql.orig/doc/src/sgml/ref/create_table.sgml pgsql/doc/src/sgml/ref/create_table.sgml
--- pgsql.orig/doc/src/sgml/ref/create_table.sgml	2006-07-11 16:09:33.000000000 +0200
+++ pgsql/doc/src/sgml/ref/create_table.sgml	2006-08-09 17:20:19.000000000 +0200
@@ -21,7 +21,9 @@ PostgreSQL documentation
  <refsynopsisdiv>
 <synopsis>
 CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PARAMETER">table_name</replaceable> ( [
-  { <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ DEFAULT <replaceable>default_expr</> ] [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
+  { <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable>
+    | [ { DEFAULT <replaceable>default_expr</> | GENERATED ALWAYS AS (<replaceable>default_expr</replaceable> ) | GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( <replaceable>sequence_options</replaceable> ) ] } ]
+    | [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
     | <replaceable>table_constraint</replaceable>
     | LIKE <replaceable>parent_table</replaceable> [ { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS } ] ... }
     [, ... ]
@@ -186,6 +188,42 @@ and <replaceable class="PARAMETER">table
    </varlistentry>
 
    <varlistentry>
+    <term><literal>GENERATED ALWAYS AS (
+    <replaceable>default_expr</replaceable> ) </literal></term>
+    <listitem>
+     <para>
+      This is similar to the <literal>DEFAULT</> clause, except
+      in an insert operation, where the default data value will
+      be used for the column even when an expression is specified.
+     </para>
+    </listitem>
+   </varlistentry>
+
+   <varlistentry>
+    <term><literal>GENERATED { ALWAYS BY DEFAULT } AS IDENTITY (
+    <replaceable>sequence_options</replaceable> ) </literal></term>
+    <listitem>
+     <para>
+      This clause creates an identity column, whose default value
+      will be generated by an automatically created sequence.
+      For the <literal>SERIAL</> type this is implicit.
+      However, any type that has implicit cast from bigint
+      can be specified for the column.
+     </para>
+
+     <para>
+      With <literal>GENERATED ALWAYS AS IDENTITY</literal>, the default value
+      will always be used in an insert operation.
+      With this feature, one can approximate the
+      autoincrementer type that other DBMSs provide, e.g.
+      <literal>INSERT INTO table (id, ... ) VALUES (0, ...);</literal>
+      will insert a new column with the next sequence value
+      instead of 0.
+     </para>
+    </listitem>
+   </varlistentry>
+
+   <varlistentry>
     <term><literal>INHERITS ( <replaceable>parent_table</replaceable> [, ... ] )</literal></term>
     <listitem>
      <para>
diff -durpN pgsql.orig/doc/src/sgml/ref/insert.sgml pgsql/doc/src/sgml/ref/insert.sgml
--- pgsql.orig/doc/src/sgml/ref/insert.sgml	2005-11-17 23:14:51.000000000 +0100
+++ pgsql/doc/src/sgml/ref/insert.sgml	2006-08-09 17:20:19.000000000 +0200
@@ -21,7 +21,7 @@ PostgreSQL documentation
  <refsynopsisdiv>
 <synopsis>
 INSERT INTO <replaceable class="PARAMETER">table</replaceable> [ ( <replaceable class="PARAMETER">column</replaceable> [, ...] ) ]
-    { DEFAULT VALUES | VALUES ( { <replaceable class="PARAMETER">expression</replaceable> | DEFAULT } [, ...] ) | <replaceable class="PARAMETER">query</replaceable> }
+    [ OVERRIDING { SYSTEM | USER } VALUE ] { DEFAULT VALUES | VALUES ( { <replaceable class="PARAMETER">expression</replaceable> | DEFAULT } [, ...] ) | <replaceable class="PARAMETER">query</replaceable> }
 </synopsis>
  </refsynopsisdiv>
 
@@ -90,6 +90,22 @@ INSERT INTO <replaceable class="PARAMETE
    </varlistentry>
 
    <varlistentry>
+    <term><literal>OVERRIDING { SYSTEM | USER } VALUE</literal></term>
+    <listitem>
+     <para>
+      The <literal>OVERRIDING SYSTEM VALUE</literal> clause can be used
+      to override default values for columns that were defined as
+      <literal>GENERATED ALWAYS</literal>. Omitting the <literal>OVERRIDING</literal> clause or
+      specifying <literal>OVERRIDING USER VALUE</literal> enforces the default value
+      for such columns. Only effective for the table owner and
+      the database superuser. It has no effect on regular columns
+      with or without <literal>DEFAULT</literal> values or
+      on <literal>GENERATED BY DEFAULT AS IDENTITY</literal> columns.
+     </para>
+    </listitem>
+   </varlistentry>
+
+   <varlistentry>
     <term><literal>DEFAULT VALUES</literal></term>
     <listitem>
      <para>
diff -durpN pgsql.orig/doc/src/sgml/ref/update.sgml pgsql/doc/src/sgml/ref/update.sgml
--- pgsql.orig/doc/src/sgml/ref/update.sgml	2006-03-08 23:59:09.000000000 +0100
+++ pgsql/doc/src/sgml/ref/update.sgml	2006-08-09 17:20:19.000000000 +0200
@@ -267,6 +267,13 @@ COMMIT;
    <literal>FROM</>.  Be careful when porting applications that use this
    extension.
   </para>
+
+  <para>
+   UPDATE always fails for GENERATED ALWAYS AS IDENTITY columns
+   and fails for GENERATED ALWAYS AS ( expr ) columns when
+   other than the <literal>DEFAULT</literal> literal appears as
+   the expression on the right side of the assignment.
+  </para>
  </refsect1>
 </refentry>
 
diff -durpN pgsql.orig/src/backend/access/common/tupdesc.c pgsql/src/backend/access/common/tupdesc.c
--- pgsql.orig/src/backend/access/common/tupdesc.c	2006-07-29 23:43:53.000000000 +0200
+++ pgsql/src/backend/access/common/tupdesc.c	2006-08-09 17:20:19.000000000 +0200
@@ -142,6 +142,8 @@ CreateTupleDescCopy(TupleDesc tupdesc)
 		memcpy(desc->attrs[i], tupdesc->attrs[i], ATTRIBUTE_TUPLE_SIZE);
 		desc->attrs[i]->attnotnull = false;
 		desc->attrs[i]->atthasdef = false;
+		desc->attrs[i]->attidentity = false;
+		desc->attrs[i]->attforceddef = false;
 	}
 
 	desc->tdtypeid = tupdesc->tdtypeid;
@@ -356,6 +358,10 @@ equalTupleDescs(TupleDesc tupdesc1, Tupl
 			return false;
 		if (attr1->attinhcount != attr2->attinhcount)
 			return false;
+		if (attr1->attidentity != attr2->attidentity)
+			return false;
+		if (attr1->attforceddef != attr2->attforceddef)
+			return false;
 	}
 
 	if (tupdesc1->constr != NULL)
@@ -471,6 +477,8 @@ TupleDescInitEntry(TupleDesc desc,
 	att->attisdropped = false;
 	att->attislocal = true;
 	att->attinhcount = 0;
+	att->attidentity = false;
+	att->attforceddef = false;
 
 	tuple = SearchSysCache(TYPEOID,
 						   ObjectIdGetDatum(oidtypeid),
@@ -563,6 +571,8 @@ BuildDescForRelation(List *schema)
 			attrdef[ndef].adbin = pstrdup(entry->cooked_default);
 			ndef++;
 			desc->attrs[attnum - 1]->atthasdef = true;
+			desc->attrs[attnum - 1]->attidentity = entry->is_identity;
+			desc->attrs[attnum - 1]->attforceddef = entry->force_default;
 		}
 
 		desc->attrs[attnum - 1]->attislocal = entry->is_local;
diff -durpN pgsql.orig/src/backend/catalog/aclchk.c pgsql/src/backend/catalog/aclchk.c
--- pgsql.orig/src/backend/catalog/aclchk.c	2006-07-29 23:43:59.000000000 +0200
+++ pgsql/src/backend/catalog/aclchk.c	2006-08-09 17:20:19.000000000 +0200
@@ -26,6 +26,7 @@
 #include "catalog/pg_authid.h"
 #include "catalog/pg_conversion.h"
 #include "catalog/pg_database.h"
+#include "catalog/pg_depend.h"
 #include "catalog/pg_language.h"
 #include "catalog/pg_namespace.h"
 #include "catalog/pg_opclass.h"
@@ -707,6 +708,43 @@ ExecGrant_Relation(InternalGrant *istmt)
 							  noldmembers, oldmembers,
 							  nnewmembers, newmembers);
 
+		/*
+		 * If it's a {GRANT|REVOKE} {UPDATE|INSERT|ALL}
+		 * on a table with IDENTITY columns then
+		 * issue the same with ALL on the supporting sequence.
+		 */
+		if (istmt->objtype == ACL_OBJECT_RELATION &&
+			pg_class_tuple->relkind == RELKIND_SEQUENCE &&
+			(istmt->privileges & (ACL_UPDATE|ACL_INSERT)))
+		{
+			InternalGrant	seq_istmt;
+			Oid		sequenceId;
+			int		idx;
+
+			seq_istmt.is_grant = istmt->is_grant;
+			seq_istmt.objtype = ACL_OBJECT_SEQUENCE;
+			seq_istmt.all_privs = true;
+			seq_istmt.privileges = ACL_ALL_RIGHTS_SEQUENCE;
+			seq_istmt.grantees = istmt->grantees;
+			/* don't give out GRANT on the supporting sequence */
+			seq_istmt.grant_option = false;
+			seq_istmt.behavior = istmt->behavior;
+			seq_istmt.objects = NIL;
+			for (idx = 0; idx < relation->rd_att->natts; idx++)
+			{
+				if (relation->rd_att->attrs[idx]->attisdropped)
+					continue;
+				if (relation->rd_att->attrs[idx]->attidentity)
+				{
+					sequenceId = get_relid_att_serial_sequence(relOid, idx);
+					if (OidIsValid(sequenceId))
+						seq_istmt.objects = lappend_oid(seq_istmt.objects, sequenceId);
+				}
+			}
+			if (seq_istmt.objects)
+				ExecGrantStmt_oids(&seq_istmt);
+		}
+
 		ReleaseSysCache(tuple);
 
 		pfree(new_acl);
@@ -718,6 +756,126 @@ ExecGrant_Relation(InternalGrant *istmt)
 	heap_close(relation, RowExclusiveLock);
 }
 
+/*
+ *	This is called when a new IDENTITY column is
+ *	added to the table. It adds UPDATE permission
+ *	for those who have INSERT or UPDATE permission
+ *	on the table over the newly created sequence.
+ */
+void
+ExecGrant_Sequence(Oid relOid, int attnum, Oid seqOid)
+{
+	Relation	relation;
+	Datum		aclDatum;
+	Form_pg_class pg_class_tuple;
+	bool		isNull;
+	AclMode		avail_goptions;
+	AclMode		this_privileges;
+	Acl		   *acl;
+	AclItem		   *acl_p;
+	Oid			grantorId;
+	Oid			ownerId;
+	HeapTuple	tuple;
+	int			noldmembers;
+	Oid		   *oldmembers;
+	InternalGrant	istmt;
+	int		idx;
+
+	/*
+	 * Fill istmt in advance.
+	 */
+	istmt.is_grant = true;
+	istmt.objtype = ACL_OBJECT_SEQUENCE;
+	istmt.all_privs = true;
+	istmt.privileges = ACL_ALL_RIGHTS_SEQUENCE;
+	istmt.grantees = NULL;
+	istmt.grant_option = false;
+	istmt.behavior = DROP_RESTRICT;
+	istmt.objects = NULL;
+
+	relation = heap_open(RelationRelationId, RowExclusiveLock);
+
+	tuple = SearchSysCache(RELOID,
+				   ObjectIdGetDatum(relOid),
+				   0, 0, 0);
+	if (!HeapTupleIsValid(tuple))
+		elog(ERROR, "cache lookup failed for relation %u", relOid);
+	pg_class_tuple = (Form_pg_class) GETSTRUCT(tuple);
+
+	/* Not sensible to grant on an index */
+	if (pg_class_tuple->relkind == RELKIND_INDEX)
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("\"%s\" is an index",
+						NameStr(pg_class_tuple->relname))));
+
+	/* Composite types aren't tables either */
+	if (pg_class_tuple->relkind == RELKIND_COMPOSITE_TYPE)
+		ereport(ERROR,
+				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
+				 errmsg("\"%s\" is a composite type",
+						NameStr(pg_class_tuple->relname))));
+
+	/*
+	 * Get owner ID and working copy of existing ACL. If there's no ACL,
+	 * substitute the proper default.
+	 */
+	ownerId = pg_class_tuple->relowner;
+	aclDatum = SysCacheGetAttr(RELOID, tuple, Anum_pg_class_relacl,
+							   &isNull);
+	if (isNull)
+		acl = acldefault(ACL_OBJECT_RELATION, ownerId);
+	else
+		acl = DatumGetAclPCopy(aclDatum);
+
+	/* Determine ID to do the grant as, and available grant options */
+	this_privileges = ACL_ALL_RIGHTS_SEQUENCE;
+	select_best_grantor(GetUserId(), this_privileges,
+						acl, ownerId,
+						&grantorId, &avail_goptions);
+
+	/*
+	 * Restrict the privileges to what we can actually grant, and emit
+	 * the standards-mandated warning and error messages.
+	 */
+	this_privileges =
+		restrict_and_check_grant(false, avail_goptions,
+								 true,
+								 this_privileges,
+								 relOid, grantorId,
+								 ACL_KIND_CLASS,
+								 NameStr(pg_class_tuple->relname));
+
+	noldmembers = aclmembers(acl, &oldmembers);
+	if (noldmembers == 0)
+		goto out;
+
+	acl_p = ACL_DAT(acl);
+
+	/*
+	 * If a grantee has {UPDATE|INSERT|ALL}
+	 * on a table then issue GRANT ALL
+	 * on the supporting sequence for her.
+	 */
+	for (idx = 0; idx < noldmembers; idx++)
+	{
+		if (ACLITEM_GET_PRIVS(acl_p[idx]) & (ACL_UPDATE|ACL_INSERT))
+			istmt.grantees = lappend_oid(istmt.grantees, oldmembers[idx]);
+	}
+	istmt.objects = list_make1_oid(seqOid);
+
+out:
+	ReleaseSysCache(tuple);
+
+	/* prevent error when processing duplicate objects */
+	CommandCounterIncrement();
+
+	heap_close(relation, RowExclusiveLock);
+
+	if (istmt.grantees != NULL)
+		ExecGrant_Relation(&istmt);
+}
+
 static void
 ExecGrant_Database(InternalGrant *istmt)
 {
diff -durpN pgsql.orig/src/backend/catalog/heap.c pgsql/src/backend/catalog/heap.c
--- pgsql.orig/src/backend/catalog/heap.c	2006-08-03 10:37:43.000000000 +0200
+++ pgsql/src/backend/catalog/heap.c	2006-08-09 17:20:19.000000000 +0200
@@ -1202,6 +1202,8 @@ RemoveAttrDefaultById(Oid attrdefId)
 			 myattnum, myrelid);
 
 	((Form_pg_attribute) GETSTRUCT(tuple))->atthasdef = false;
+	((Form_pg_attribute) GETSTRUCT(tuple))->attidentity = false;
+	((Form_pg_attribute) GETSTRUCT(tuple))->attforceddef = false;
 
 	simple_heap_update(attr_rel, &tuple->t_self, tuple);
 
@@ -1295,7 +1297,7 @@ heap_drop_with_catalog(Oid relid)
  * The expression must be presented as a nodeToString() string.
  */
 void
-StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin)
+StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin, bool attidentity, bool attforceddef)
 {
 	Node	   *expr;
 	char	   *adsrc;
@@ -1368,6 +1370,8 @@ StoreAttrDefault(Relation rel, AttrNumbe
 	if (!attStruct->atthasdef)
 	{
 		attStruct->atthasdef = true;
+		attStruct->attidentity = attidentity;
+		attStruct->attforceddef = attforceddef;
 		simple_heap_update(attrrel, &atttup->t_self, atttup);
 		/* keep catalog indexes current */
 		CatalogUpdateIndexes(attrrel, atttup);
@@ -1504,7 +1508,8 @@ StoreConstraints(Relation rel, TupleDesc
 
 	for (i = 0; i < constr->num_defval; i++)
 		StoreAttrDefault(rel, constr->defval[i].adnum,
-						 constr->defval[i].adbin);
+						 constr->defval[i].adbin,
+						 false, false);
 
 	for (i = 0; i < constr->num_check; i++)
 		StoreRelCheck(rel, constr->check[i].ccname,
@@ -1589,13 +1594,14 @@ AddRelationRawConstraints(Relation rel,
 						   atp->atttypid, atp->atttypmod,
 						   NameStr(atp->attname));
 
-		StoreAttrDefault(rel, colDef->attnum, nodeToString(expr));
+		StoreAttrDefault(rel, colDef->attnum, nodeToString(expr), colDef->is_identity, colDef->force_default);
 
 		cooked = (CookedConstraint *) palloc(sizeof(CookedConstraint));
 		cooked->contype = CONSTR_DEFAULT;
 		cooked->name = NULL;
 		cooked->attnum = colDef->attnum;
 		cooked->expr = expr;
+		cooked->force_default = colDef->force_default;
 		cookedConstraints = lappend(cookedConstraints, cooked);
 	}
 
@@ -1810,6 +1816,7 @@ cookDefault(ParseState *pstate,
 	 */
 	expr = transformExpr(pstate, raw_default);
 
+#if 1 /* Lift this restriction somehow, for e.g. GENERATED ALWAYS AS ( col1 + col2 ) */
 	/*
 	 * Make sure default expr does not refer to any vars.
 	 */
@@ -1817,6 +1824,7 @@ cookDefault(ParseState *pstate,
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
 			  errmsg("cannot use column references in default expression")));
+#endif
 
 	/*
 	 * It can't return a set either.
diff -durpN pgsql.orig/src/backend/catalog/index.c pgsql/src/backend/catalog/index.c
--- pgsql.orig/src/backend/catalog/index.c	2006-08-01 16:12:46.000000000 +0200
+++ pgsql/src/backend/catalog/index.c	2006-08-09 17:20:19.000000000 +0200
@@ -146,6 +146,8 @@ ConstructTupleDescriptor(Relation heapRe
 			to->atthasdef = false;
 			to->attislocal = true;
 			to->attinhcount = 0;
+			to->attidentity = false;
+			to->attforceddef = false;
 		}
 		else
 		{
diff -durpN pgsql.orig/src/backend/commands/copy.c pgsql/src/backend/commands/copy.c
--- pgsql.orig/src/backend/commands/copy.c	2006-07-29 23:44:01.000000000 +0200
+++ pgsql/src/backend/commands/copy.c	2006-08-09 17:20:19.000000000 +0200
@@ -149,6 +149,8 @@ typedef struct CopyStateData
 	char	   *raw_buf;
 	int			raw_buf_index;	/* next byte to process */
 	int			raw_buf_len;	/* total # of bytes stored */
+
+	bool			overriding;	/* OVERRIDING SYSTEM VALUE */
 } CopyStateData;
 
 typedef CopyStateData *CopyState;
@@ -708,6 +710,7 @@ DoCopy(const CopyStmt *stmt)
 	AclResult	aclresult;
 	ListCell   *option;
 	uint64		processed;
+	bool		hasforceddef;
 
 	/* Allocate workspace and zero all fields */
 	cstate = (CopyStateData *) palloc0(sizeof(CopyStateData));
@@ -1018,6 +1021,7 @@ DoCopy(const CopyStmt *stmt)
 	cstate->encoding_embeds_ascii = PG_ENCODING_IS_CLIENT_ONLY(cstate->client_encoding);
 
 	cstate->copy_dest = COPY_FILE;		/* default */
+	cstate->overriding = stmt->overriding;	/* OVERRIDING SYSTEM VALUE */
 
 	if (is_from)
 	{							/* copy from file to database */
@@ -1039,6 +1043,27 @@ DoCopy(const CopyStmt *stmt)
 						 errmsg("cannot copy to non-table relation \"%s\"",
 								RelationGetRelationName(cstate->rel))));
 		}
+		if (cstate->overriding)
+		{
+			TupleDesc	tupDesc = RelationGetDescr(cstate->rel);
+			Form_pg_attribute *attr = tupDesc->attrs;
+			int		idx;
+
+			hasforceddef = false;
+			for (idx = 0; idx < tupDesc->natts; idx++)
+			{
+				if (attr[idx]->attisdropped)
+					continue;
+				hasforceddef |= attr[idx]->attforceddef;
+			}
+			if (hasforceddef)
+			{
+				Oid	relid = RangeVarGetRelid(relation, false);
+				if (!pg_class_ownercheck(relid, GetUserId()))
+					aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,
+								get_rel_name(relid));
+			}
+		}
 		if (pipe)
 		{
 			if (whereToSendOutput == DestRemote)
@@ -1622,7 +1647,8 @@ CopyFrom(CopyState cstate)
 			force_notnull[attnum - 1] = false;
 
 		/* Get default info if needed */
-		if (!list_member_int(cstate->attnumlist, attnum))
+		if (!list_member_int(cstate->attnumlist, attnum) ||
+			(attr[attnum - 1]->attforceddef && !cstate->overriding))
 		{
 			/* attribute is NOT to be copied from input */
 			/* use default value if one exists */
diff -durpN pgsql.orig/src/backend/commands/sequence.c pgsql/src/backend/commands/sequence.c
--- pgsql.orig/src/backend/commands/sequence.c	2006-08-01 16:12:47.000000000 +0200
+++ pgsql/src/backend/commands/sequence.c	2006-08-09 17:20:19.000000000 +0200
@@ -124,6 +124,8 @@ DefineSequence(CreateSeqStmt *seq)
 		coldef->cooked_default = NULL;
 		coldef->constraints = NIL;
 		coldef->support = NULL;
+		coldef->is_identity = false;
+		coldef->force_default = false;
 
 		null[i - 1] = ' ';
 
diff -durpN pgsql.orig/src/backend/commands/tablecmds.c pgsql/src/backend/commands/tablecmds.c
--- pgsql.orig/src/backend/commands/tablecmds.c	2006-08-05 16:46:46.000000000 +0200
+++ pgsql/src/backend/commands/tablecmds.c	2006-08-09 17:22:13.000000000 +0200
@@ -33,6 +33,7 @@
 #include "catalog/toasting.h"
 #include "commands/cluster.h"
 #include "commands/defrem.h"
+#include "commands/sequence.h"
 #include "commands/tablecmds.h"
 #include "commands/tablespace.h"
 #include "commands/trigger.h"
@@ -255,6 +256,7 @@ static void ATExecEnableDisableTrigger(R
 						   bool enable, bool skip_system);
 static void ATExecAddInherits(Relation rel, RangeVar *parent);
 static void ATExecDropInherits(Relation rel, RangeVar *parent);
+static void ATExecAlterSeq(Relation rel, char *column, List *seq_opts);
 static void copy_relation_data(Relation rel, SMgrRelation dst);
 static void update_ri_trigger_args(Oid relid,
 					   const char *oldname,
@@ -500,6 +502,8 @@ DefineRelation(CreateStmt *stmt, char re
 			rawEnt = (RawColumnDefault *) palloc(sizeof(RawColumnDefault));
 			rawEnt->attnum = attnum;
 			rawEnt->raw_default = colDef->raw_default;
+			rawEnt->is_identity = colDef->is_identity;
+			rawEnt->force_default = colDef->force_default;
 			rawDefaults = lappend(rawDefaults, rawEnt);
 		}
 
@@ -945,6 +949,8 @@ MergeAttributes(List *schema, List *supe
 				def->cooked_default = NULL;
 				def->constraints = NIL;
 				def->support = NULL;
+				def->is_identity = false;
+				def->force_default = false;
 				inhSchema = lappend(inhSchema, def);
 				newattno[parent_attno - 1] = ++child_attno;
 			}
@@ -989,6 +995,8 @@ MergeAttributes(List *schema, List *supe
 					def->cooked_default = bogus_marker;
 					have_bogus_defaults = true;
 				}
+				def->is_identity = attribute->attidentity;
+				def->force_default = attribute->attforceddef;
 			}
 		}
 
@@ -1074,6 +1082,8 @@ MergeAttributes(List *schema, List *supe
 				{
 					def->raw_default = newdef->raw_default;
 					def->cooked_default = newdef->cooked_default;
+					def->is_identity = newdef->is_identity;
+					def->force_default = newdef->force_default;
 				}
 			}
 			else
@@ -1356,6 +1366,32 @@ setRelhassubclassInRelation(Oid relation
 	heap_close(relationRelation, RowExclusiveLock);
 }
 
+static void renameseqfor(Oid tableOid, const char *newrelname, const char *oldattname, const char *newattname)
+{
+	int		attnum;
+	Oid		sequenceId;
+
+	if (!newrelname)
+		newrelname = get_rel_name(tableOid);
+	attnum = get_attnum(tableOid, oldattname);
+	if (attnum == InvalidAttrNumber)
+		return;
+
+	sequenceId = get_relid_att_serial_sequence(tableOid, attnum);
+
+	if (OidIsValid(sequenceId))
+	{
+		char 		*sname;
+		
+		sname = ChooseRelationName(newrelname,
+							newattname,
+							"seq",
+							get_rel_namespace(sequenceId));
+		renamerel(sequenceId, sname);
+		elog(NOTICE, "supporting sequence for column \"%s\" renamed to \"%s\"", newattname, sname);
+		pfree(sname);
+	}
+}
 
 /*
  *		renameatt		- changes the name of a attribute in a relation
@@ -1574,6 +1610,12 @@ renameatt(Oid myrelid,
 	}
 
 	relation_close(targetrelation, NoLock);		/* close rel but keep lock */
+
+	/*
+	 * Also rename the underlying sequence
+	 * if this column is GENERATED AS IDENTITY.
+	 */
+	renameseqfor(myrelid, NULL, oldattname, newattname);
 }
 
 /*
@@ -1595,6 +1637,7 @@ renamerel(Oid myrelid, const char *newre
 	char	   *oldrelname;
 	char		relkind;
 	bool		relhastriggers;
+	int		idx;
 
 	/*
 	 * Grab an exclusive lock on the target table or index, which we will NOT
@@ -1642,6 +1685,15 @@ renamerel(Oid myrelid, const char *newre
 	/* keep the system catalog indexes current */
 	CatalogUpdateIndexes(relrelation, reltup);
 
+	for (idx = 0; idx < targetrelation->rd_att->natts; idx++)
+	{
+		char	*attname;
+		if (targetrelation->rd_att->attrs[idx]->attisdropped)
+			continue;
+		attname = NameStr(targetrelation->rd_att->attrs[idx]->attname);
+		renameseqfor(myrelid, newrelname, attname, attname);
+	}
+
 	heap_freetuple(reltup);
 	heap_close(relrelation, RowExclusiveLock);
 
@@ -2118,6 +2170,7 @@ ATPrepCmd(List **wqueue, Relation rel, A
 		case AT_DisableTrigUser:
 		case AT_AddInherits:
 		case AT_DropInherits:
+		case AT_SetSeqOpts:
 			ATSimplePermissions(rel, false);
 			/* These commands never recurse */
 			/* No command-specific prep needed */
@@ -2307,6 +2360,9 @@ ATExecCmd(AlteredTableInfo *tab, Relatio
 		case AT_AddInherits:
 			ATExecAddInherits(rel, cmd->parent);
 			break;
+		case AT_SetSeqOpts:
+			ATExecAlterSeq(rel, cmd->name, (List *)cmd->def);
+			break;
 		default:				/* oops */
 			elog(ERROR, "unrecognized alter table type: %d",
 				 (int) cmd->subtype);
@@ -3156,6 +3212,8 @@ ATExecAddColumn(AlteredTableInfo *tab, R
 	attribute->attisdropped = false;
 	attribute->attislocal = colDef->is_local;
 	attribute->attinhcount = colDef->inhcount;
+	attribute->attidentity = false;
+	attribute->attforceddef = false;
 
 	ReleaseSysCache(typeTuple);
 
@@ -3193,6 +3251,8 @@ ATExecAddColumn(AlteredTableInfo *tab, R
 		rawEnt = (RawColumnDefault *) palloc(sizeof(RawColumnDefault));
 		rawEnt->attnum = attribute->attnum;
 		rawEnt->raw_default = copyObject(colDef->raw_default);
+		rawEnt->is_identity = colDef->is_identity;
+		rawEnt->force_default = colDef->force_default;
 
 		/*
 		 * This function is intended for CREATE TABLE, so it processes a
@@ -3289,14 +3349,17 @@ add_column_support_dependency(Oid relid,
 {
 	ObjectAddress colobject,
 				suppobject;
+	Oid	seqId = RangeVarGetRelid(support, false);;
 
 	colobject.classId = RelationRelationId;
 	colobject.objectId = relid;
 	colobject.objectSubId = attnum;
 	suppobject.classId = RelationRelationId;
-	suppobject.objectId = RangeVarGetRelid(support, false);
+	suppobject.objectId = seqId;
 	suppobject.objectSubId = 0;
 	recordDependencyOn(&suppobject, &colobject, DEPENDENCY_INTERNAL);
+
+	ExecGrant_Sequence(relid, attnum, seqId);
 }
 
 /*
@@ -3470,6 +3533,18 @@ ATExecColumnDefault(Relation rel, const 
 				 errmsg("cannot alter system column \"%s\"",
 						colName)));
 
+	if (rel->rd_att->attrs[attnum - 1]->attidentity)
+		ereport(ERROR,
+				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+				 errmsg("cannot alter IDENTITY column \"%s\"",
+				 		colName)));
+
+	if (rel->rd_att->attrs[attnum - 1]->attforceddef)
+		ereport(ERROR,
+				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+				 errmsg("cannot alter GENERATED column \"%s\"",
+				 		colName)));
+
 	/*
 	 * Remove any old default for the column.  We use RESTRICT here for
 	 * safety, but at present we do not expect anything to depend on the
@@ -3485,6 +3560,8 @@ ATExecColumnDefault(Relation rel, const 
 		rawEnt = (RawColumnDefault *) palloc(sizeof(RawColumnDefault));
 		rawEnt->attnum = attnum;
 		rawEnt->raw_default = newDefault;
+		rawEnt->is_identity = false;
+		rawEnt->force_default = false;
 
 		/*
 		 * This function is intended for CREATE TABLE, so it processes a
@@ -4988,6 +5065,8 @@ ATExecAlterColumnType(AlteredTableInfo *
 	ScanKeyData key[3];
 	SysScanDesc scan;
 	HeapTuple	depTup;
+	bool		attidentity;
+	bool		attforceddef;
 
 	attrelation = heap_open(AttributeRelationId, RowExclusiveLock);
 
@@ -5044,6 +5123,8 @@ ATExecAlterColumnType(AlteredTableInfo *
 	}
 	else
 		defaultexpr = NULL;
+	attidentity = attTup->attidentity;
+	attforceddef = attTup->attforceddef;
 
 	/*
 	 * Find everything that depends on the column (constraints, indexes, etc),
@@ -5292,7 +5373,7 @@ ATExecAlterColumnType(AlteredTableInfo *
 		 */
 		RemoveAttrDefault(RelationGetRelid(rel), attnum, DROP_RESTRICT, true);
 
-		StoreAttrDefault(rel, attnum, nodeToString(defaultexpr));
+		StoreAttrDefault(rel, attnum, nodeToString(defaultexpr), attidentity, attforceddef);
 	}
 
 	/* Cleanup */
@@ -6177,6 +6258,58 @@ ATExecAddInherits(Relation child_rel, Ra
 }
 
 /*
+ * ALTER TABLE RESTART WITH / SET sequence_options
+ */
+static void
+ATExecAlterSeq(Relation rel, char *column, List *seq_opts)
+{
+	Oid		tableOid;
+	AttrNumber	attnum;
+	Oid		sequenceId;
+
+	tableOid = RelationGetRelid(rel);
+	attnum = get_attnum(tableOid, column);
+	sequenceId = get_relid_att_serial_sequence(tableOid, attnum);
+	if (OidIsValid(sequenceId))
+	{
+		HeapTuple	seqtup;
+
+		seqtup = SearchSysCache(RELOID,
+						ObjectIdGetDatum(sequenceId),
+						0, 0, 0);
+		if (HeapTupleIsValid(seqtup))
+		{
+			Form_pg_class seq = (Form_pg_class) GETSTRUCT(seqtup);
+			HeapTuple	nsptup;
+			RangeVar   *rv = NULL;
+
+			nsptup = SearchSysCache(NAMESPACEOID,
+							ObjectIdGetDatum(seq->relnamespace),
+							0, 0, 0);
+			if (HeapTupleIsValid(nsptup))
+			{
+				Form_pg_namespace nsp = (Form_pg_namespace) GETSTRUCT(nsptup);
+				rv = makeRangeVar(NameStr(nsp->nspname), NameStr(seq->relname));
+				ReleaseSysCache(nsptup);
+			}
+			
+			ReleaseSysCache(seqtup);
+
+			if (rv != NULL)
+			{
+				AlterSeqStmt	*newcmd;
+
+				newcmd = makeNode(AlterSeqStmt);
+				newcmd->sequence = rv;
+				newcmd->options = seq_opts;
+				AlterSequence(newcmd);
+			}
+		}
+	} else
+		elog(ERROR, "RESTART WITH/SET sequence_opts can be used only on IDENTITY columns");
+}
+
+/*
  * Check columns in child table match up with columns in parent
  *
  * Called by ATExecAddInherits
diff -durpN pgsql.orig/src/backend/commands/view.c pgsql/src/backend/commands/view.c
--- pgsql.orig/src/backend/commands/view.c	2006-07-14 13:51:52.000000000 +0200
+++ pgsql/src/backend/commands/view.c	2006-08-09 17:20:19.000000000 +0200
@@ -127,6 +127,8 @@ DefineVirtualRelation(const RangeVar *re
 			def->cooked_default = NULL;
 			def->constraints = NIL;
 			def->support = NULL;
+			def->is_identity;
+			def->force_default = false;
 
 			attrList = lappend(attrList, def);
 		}
diff -durpN pgsql.orig/src/backend/nodes/copyfuncs.c pgsql/src/backend/nodes/copyfuncs.c
--- pgsql.orig/src/backend/nodes/copyfuncs.c	2006-08-03 10:37:45.000000000 +0200
+++ pgsql/src/backend/nodes/copyfuncs.c	2006-08-09 17:20:19.000000000 +0200
@@ -1642,6 +1642,8 @@ _copyColumnDef(ColumnDef *from)
 	COPY_STRING_FIELD(cooked_default);
 	COPY_NODE_FIELD(constraints);
 	COPY_NODE_FIELD(support);
+	COPY_SCALAR_FIELD(is_identity);
+	COPY_SCALAR_FIELD(force_default);
 
 	return newnode;
 }
@@ -1658,6 +1660,8 @@ _copyConstraint(Constraint *from)
 	COPY_NODE_FIELD(keys);
 	COPY_NODE_FIELD(options);
 	COPY_STRING_FIELD(indexspace);
+	COPY_SCALAR_FIELD(force_default);
+	COPY_NODE_FIELD(seq_opts);
 
 	return newnode;
 }
@@ -1713,6 +1717,7 @@ _copyQuery(Query *from)
 	COPY_NODE_FIELD(rowMarks);
 	COPY_NODE_FIELD(setOperations);
 	COPY_NODE_FIELD(resultRelations);
+	COPY_SCALAR_FIELD(commandOverride);
 
 	return newnode;
 }
@@ -1725,6 +1730,7 @@ _copyInsertStmt(InsertStmt *from)
 	COPY_NODE_FIELD(relation);
 	COPY_NODE_FIELD(cols);
 	COPY_NODE_FIELD(selectStmt);
+	COPY_SCALAR_FIELD(override_def);
 
 	return newnode;
 }
diff -durpN pgsql.orig/src/backend/nodes/equalfuncs.c pgsql/src/backend/nodes/equalfuncs.c
--- pgsql.orig/src/backend/nodes/equalfuncs.c	2006-08-03 10:37:45.000000000 +0200
+++ pgsql/src/backend/nodes/equalfuncs.c	2006-08-09 17:20:19.000000000 +0200
@@ -673,6 +673,7 @@ _equalQuery(Query *a, Query *b)
 	COMPARE_NODE_FIELD(rowMarks);
 	COMPARE_NODE_FIELD(setOperations);
 	COMPARE_NODE_FIELD(resultRelations);
+	COMPARE_SCALAR_FIELD(commandOverride);
 
 	return true;
 }
@@ -683,6 +684,7 @@ _equalInsertStmt(InsertStmt *a, InsertSt
 	COMPARE_NODE_FIELD(relation);
 	COMPARE_NODE_FIELD(cols);
 	COMPARE_NODE_FIELD(selectStmt);
+	COMPARE_SCALAR_FIELD(override_def);
 
 	return true;
 }
@@ -1660,6 +1662,8 @@ _equalColumnDef(ColumnDef *a, ColumnDef 
 	COMPARE_STRING_FIELD(cooked_default);
 	COMPARE_NODE_FIELD(constraints);
 	COMPARE_NODE_FIELD(support);
+	COMPARE_SCALAR_FIELD(is_identity);
+	COMPARE_SCALAR_FIELD(force_default);
 
 	return true;
 }
@@ -1674,6 +1678,8 @@ _equalConstraint(Constraint *a, Constrai
 	COMPARE_NODE_FIELD(keys);
 	COMPARE_NODE_FIELD(options);
 	COMPARE_STRING_FIELD(indexspace);
+	COMPARE_SCALAR_FIELD(force_default);
+	COMPARE_NODE_FIELD(seq_opts);
 
 	return true;
 }
diff -durpN pgsql.orig/src/backend/nodes/outfuncs.c pgsql/src/backend/nodes/outfuncs.c
--- pgsql.orig/src/backend/nodes/outfuncs.c	2006-08-03 10:37:45.000000000 +0200
+++ pgsql/src/backend/nodes/outfuncs.c	2006-08-09 17:20:19.000000000 +0200
@@ -1445,6 +1445,8 @@ _outColumnDef(StringInfo str, ColumnDef 
 	WRITE_STRING_FIELD(cooked_default);
 	WRITE_NODE_FIELD(constraints);
 	WRITE_NODE_FIELD(support);
+	WRITE_BOOL_FIELD(is_identity);
+	WRITE_BOOL_FIELD(force_default);
 }
 
 static void
@@ -1534,6 +1536,7 @@ _outQuery(StringInfo str, Query *node)
 	WRITE_NODE_FIELD(rowMarks);
 	WRITE_NODE_FIELD(setOperations);
 	WRITE_NODE_FIELD(resultRelations);
+	WRITE_BOOL_FIELD(commandOverride);
 }
 
 static void
@@ -1795,6 +1798,12 @@ _outConstraint(StringInfo str, Constrain
 			appendStringInfo(str, "DEFAULT");
 			WRITE_NODE_FIELD(raw_expr);
 			WRITE_STRING_FIELD(cooked_expr);
+			WRITE_BOOL_FIELD(force_default);
+			break;
+
+		case CONSTR_IDENTITY:
+			appendStringInfo(str, "IDENTITY");
+			WRITE_NODE_FIELD(seq_opts);
 			break;
 
 		case CONSTR_NOTNULL:
diff -durpN pgsql.orig/src/backend/nodes/readfuncs.c pgsql/src/backend/nodes/readfuncs.c
--- pgsql.orig/src/backend/nodes/readfuncs.c	2006-08-03 10:37:45.000000000 +0200
+++ pgsql/src/backend/nodes/readfuncs.c	2006-08-09 17:20:19.000000000 +0200
@@ -157,6 +157,7 @@ _readQuery(void)
 	READ_NODE_FIELD(rowMarks);
 	READ_NODE_FIELD(setOperations);
 	READ_NODE_FIELD(resultRelations);
+	READ_BOOL_FIELD(commandOverride);
 
 	READ_DONE();
 }
diff -durpN pgsql.orig/src/backend/parser/analyze.c pgsql/src/backend/parser/analyze.c
--- pgsql.orig/src/backend/parser/analyze.c	2006-08-03 10:37:47.000000000 +0200
+++ pgsql/src/backend/parser/analyze.c	2006-08-09 17:20:20.000000000 +0200
@@ -532,6 +532,7 @@ transformInsertStmt(ParseState *pstate, 
 	ListCell   *lc;
 
 	qry->commandType = CMD_INSERT;
+	qry->commandOverride = stmt->override_def;
 	pstate->p_is_insert = true;
 
 	/*
@@ -995,6 +996,9 @@ transformColumnDefinition(ParseState *ps
 	bool		saw_nullable;
 	Constraint *constraint;
 	ListCell   *clist;
+	bool		saw_identity;
+	bool		force_default;
+	List	   *seq_opts;
 
 	cxt->columns = lappend(cxt->columns, column);
 
@@ -1020,6 +1024,31 @@ transformColumnDefinition(ParseState *ps
 		}
 	}
 
+	/* Check for GENERATED ... AS IDENTITY constructs */
+	saw_identity = false;
+	force_default = false;
+	seq_opts = NULL;
+	foreach(clist, column->constraints)
+	{
+		constraint = lfirst(clist);
+
+		switch (constraint->contype) {
+			case CONSTR_IDENTITY:
+				if (saw_identity)
+					ereport(ERROR,
+						(errcode(ERRCODE_SYNTAX_ERROR),
+						 errmsg("multiple GENERATED ... AS IDENTITY constructs specified for column \"%s\" of table \"%s\"",
+							  column->colname, cxt->relation->relname)));
+				saw_identity = true;
+				is_serial = true;
+				force_default = constraint->force_default;
+				seq_opts = constraint->seq_opts;
+				break;
+			default:
+				continue;
+		}
+	}
+
 	/* Do necessary work on the column type declaration */
 	transformColumnType(pstate, column);
 
@@ -1064,7 +1093,7 @@ transformColumnDefinition(ParseState *ps
 		 */
 		seqstmt = makeNode(CreateSeqStmt);
 		seqstmt->sequence = makeRangeVar(snamespace, sname);
-		seqstmt->options = NIL;
+		seqstmt->options = seq_opts;
 
 		cxt->blist = lappend(cxt->blist, seqstmt);
 
@@ -1101,6 +1130,7 @@ transformColumnDefinition(ParseState *ps
 		constraint->raw_expr = (Node *) funccallnode;
 		constraint->cooked_expr = NULL;
 		constraint->keys = NIL;
+		constraint->force_default = force_default;
 		column->constraints = lappend(column->constraints, constraint);
 
 		constraint = makeNode(Constraint);
@@ -1162,9 +1192,13 @@ transformColumnDefinition(ParseState *ps
 							 errmsg("multiple default values specified for column \"%s\" of table \"%s\"",
 								  column->colname, cxt->relation->relname)));
 				column->raw_default = constraint->raw_expr;
+				force_default = constraint->force_default;
 				Assert(constraint->cooked_expr == NULL);
 				break;
 
+			case CONSTR_IDENTITY:	/* This was processed above, we only have to detect it here. */
+				break;
+
 			case CONSTR_PRIMARY:
 			case CONSTR_UNIQUE:
 				if (constraint->keys == NIL)
@@ -1189,6 +1223,8 @@ transformColumnDefinition(ParseState *ps
 				break;
 		}
 	}
+	column->is_identity = is_serial;
+	column->force_default = force_default;
 }
 
 static void
@@ -1331,6 +1367,8 @@ transformInhRelation(ParseState *pstate,
 		def->cooked_default = NULL;
 		def->constraints = NIL;
 		def->support = NULL;
+		def->is_identity = false;
+		def->force_default = false;
 
 		/*
 		 * Add to column list
@@ -1365,6 +1403,8 @@ transformInhRelation(ParseState *pstate,
 			 */
 
 			def->cooked_default = pstrdup(this_default);
+			def->is_identity = attribute->attidentity;
+			def->force_default = attribute->attforceddef;
 		}
 	}
 	
diff -durpN pgsql.orig/src/backend/parser/gram.y pgsql/src/backend/parser/gram.y
--- pgsql.orig/src/backend/parser/gram.y	2006-08-03 10:37:48.000000000 +0200
+++ pgsql/src/backend/parser/gram.y	2006-08-09 17:20:20.000000000 +0200
@@ -281,7 +281,7 @@ static void doNegateFloat(Value *v);
 
 %type <node>	fetch_direction select_limit_value select_offset_value
 
-%type <list>	OptSeqList
+%type <list>	OptSeqList SeqList
 %type <defelt>	OptSeqElem
 
 %type <istmt>	insert_rest
@@ -309,6 +309,7 @@ static void doNegateFloat(Value *v);
 %type <range>	relation_expr
 %type <range>	relation_expr_opt_alias
 %type <target>	target_el update_target_el insert_column_item
+%type <boolean>	OptOverride UserSystem
 
 %type <typnam>	Typename SimpleTypename ConstTypename
 				GenericType Numeric opt_float
@@ -337,6 +338,7 @@ static void doNegateFloat(Value *v);
 %type <ival>	TableLikeOption
 %type <list>	ColQualList
 %type <node>	ColConstraint ColConstraintElem ConstraintAttr
+%type <node>	AlwaysByDefault IdentityGenerated IdentitySpec
 %type <ival>	key_actions key_delete key_match key_update key_action
 %type <ival>	ConstraintAttributeSpec ConstraintDeferrabilitySpec
 				ConstraintTimeSpec
@@ -356,7 +358,7 @@ static void doNegateFloat(Value *v);
 
 /* ordinary key words in alphabetical order */
 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
-	AGGREGATE ALL ALSO ALTER ANALYSE ANALYZE AND ANY ARRAY AS ASC
+	AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
 	ASSERTION ASSIGNMENT ASYMMETRIC AT AUTHORIZATION
 
 	BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
@@ -379,11 +381,11 @@ static void doNegateFloat(Value *v);
 	FALSE_P FETCH FIRST_P FLOAT_P FOR FORCE FOREIGN FORWARD
 	FREEZE FROM FULL FUNCTION
 
-	GLOBAL GRANT GRANTED GREATEST GROUP_P
+	GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P
 
 	HANDLER HAVING HEADER_P HOLD HOUR_P
 
-	IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P INCLUDING INCREMENT
+	IDENTITY IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P INCLUDING INCREMENT
 	INDEX INDEXES INHERIT INHERITS INITIALLY INNER_P INOUT INPUT_P
 	INSENSITIVE INSERT INSTEAD INT_P INTEGER INTERSECT
 	INTERVAL INTO INVOKER IS ISNULL ISOLATION
@@ -403,7 +405,7 @@ static void doNegateFloat(Value *v);
 	NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF NUMERIC
 
 	OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OR
-	ORDER OUT_P OUTER_P OVERLAPS OVERLAY OWNED OWNER
+	ORDER OUT_P OUTER_P OVERLAPS OVERLAY OVERRIDING OWNED OWNER
 
 	PARTIAL PASSWORD PLACING POSITION
 	PRECISION PRESERVE PREPARE PREPARED PRIMARY
@@ -428,7 +430,7 @@ static void doNegateFloat(Value *v);
 	UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNTIL
 	UPDATE USER USING
 
-	VACUUM VALID VALIDATOR VALUES VARCHAR VARYING
+	VACUUM VALID VALIDATOR VALUE VALUES VARCHAR VARYING
 	VERBOSE VIEW VOLATILE
 
 	WHEN WHERE WITH WITHOUT WORK WRITE
@@ -1400,6 +1402,22 @@ alter_table_cmd:
 					n->def = (Node *) makeString($6);
 					$$ = (Node *)n;
 				}
+			| ALTER opt_column ColId SET SeqList
+				{
+					AlterTableCmd *n = makeNode(AlterTableCmd);
+					n->subtype = AT_SetSeqOpts;
+					n->name = $3;
+					n->def = (Node *) $5;
+					$$ = (Node *)n;
+				}
+			| ALTER opt_column ColId RESTART opt_with NumericOnly
+				{
+					AlterTableCmd *n = makeNode(AlterTableCmd);
+					n->subtype = AT_SetSeqOpts;
+					n->name = $3;
+					n->def = (Node *)list_make1(makeDefElem("restart", (Node *)$6));
+					$$ = (Node *)n;
+				}
 			/* ALTER TABLE <relation> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
 			| DROP opt_column ColId opt_drop_behavior
 				{
@@ -1621,14 +1639,15 @@ ClosePortalStmt:
  *
  *****************************************************************************/
 
-CopyStmt:	COPY opt_binary qualified_name opt_column_list opt_oids
+CopyStmt:	COPY opt_binary qualified_name opt_column_list opt_oids OptOverride
 			copy_from copy_file_name copy_delimiter opt_with copy_opt_list
 				{
 					CopyStmt *n = makeNode(CopyStmt);
 					n->relation = $3;
 					n->attlist = $4;
-					n->is_from = $6;
-					n->filename = $7;
+					n->overriding = $6;
+					n->is_from = $7;
+					n->filename = $8;
 
 					n->options = NIL;
 					/* Concatenate user-supplied flags */
@@ -1636,10 +1655,10 @@ CopyStmt:	COPY opt_binary qualified_name
 						n->options = lappend(n->options, $2);
 					if ($5)
 						n->options = lappend(n->options, $5);
-					if ($8)
-						n->options = lappend(n->options, $8);
-					if ($10)
-						n->options = list_concat(n->options, $10);
+					if ($9)
+						n->options = lappend(n->options, $9);
+					if ($11)
+						n->options = list_concat(n->options, $11);
 					$$ = (Node *)n;
 				}
 		;
@@ -1829,6 +1848,8 @@ columnDef:	ColId Typename ColQualList
 					n->typename = $2;
 					n->constraints = $3;
 					n->is_local = true;
+					n->is_identity = false;
+					n->force_default = false;
 					$$ = (Node *)n;
 				}
 		;
@@ -1878,6 +1899,11 @@ ColConstraint:
  * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
  * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
  * or be part of a_expr NOT LIKE or similar constructs).
+ *
+ * In the SQL2003 spec, DEFAULT, GENERATED ... AS IDENTITY and
+ * GENERATED ALWAYS AS () are mutually exclusive, that will
+ * be handled by analyze.c as conflicting DEFAULT constraints.
+ * - Zoltan Boszormenyi <zboszor@dunaweb.hu>
  */
 ColConstraintElem:
 			NOT NULL_P
@@ -1970,6 +1996,67 @@ ColConstraintElem:
 					n->initdeferred		= FALSE;
 					$$ = (Node *)n;
 				}
+			| GENERATED AlwaysByDefault
+				{
+					$$ = $2;
+				}
+		;
+
+AlwaysByDefault:
+		BY DEFAULT AS IDENTITY IdentitySpec
+				{
+					$$ = $5;
+				}
+		| ALWAYS AS IdentityGenerated
+				{
+					Constraint *n = (Constraint *)$3;
+					n->force_default = true;
+					$$ = (Node *)n;
+				}
+		;
+
+IdentityGenerated:
+		'(' a_expr ')'
+				{
+					Constraint *n = makeNode(Constraint);
+					n->contype = CONSTR_DEFAULT;
+					n->name = NULL;
+					n->raw_expr = $2;
+					n->cooked_expr = NULL;
+					n->keys = NULL;
+					n->indexspace = NULL;
+					$$ = (Node *)n;
+				}
+		| IDENTITY IdentitySpec
+				{
+					$$ = $2;
+				}
+		;
+
+IdentitySpec:	'(' SeqList ')'
+				{
+					Constraint *n = makeNode(Constraint);
+					n->contype = CONSTR_IDENTITY;
+					n->name = NULL;
+					n->raw_expr = NULL;
+					n->cooked_expr = NULL;
+					n->keys = NULL;
+					n->indexspace = NULL;
+					n->seq_opts = $2;
+					$$ = (Node *)n;
+				}
+		| /* EMPTY */
+				{
+					Constraint *n = makeNode(Constraint);
+					n->contype = CONSTR_IDENTITY;
+					n->name = NULL;
+					n->raw_expr = NULL;
+					n->cooked_expr = NULL;
+					n->keys = NULL;
+					n->indexspace = NULL;
+					n->seq_opts = NULL;
+					$$ = (Node *)n;
+				}
 		;
 
 /*
@@ -2276,6 +2363,8 @@ CreateAsElement:
 					n->cooked_default = NULL;
 					n->constraints = NIL;
 					n->support = NULL;
+					n->is_identity = false;
+					n->force_default = false;
 					$$ = (Node *)n;
 				}
 		;
@@ -2314,6 +2403,10 @@ OptSeqList: OptSeqList OptSeqElem					{ 
 			| /*EMPTY*/								{ $$ = NIL; }
 		;
 
+SeqList: SeqList OptSeqElem					{ $$ = lappend($1, $2); }
+			| OptSeqElem								{ $$ = list_make1($1); }
+		;
+
 OptSeqElem: CACHE NumericOnly
 				{
 					$$ = makeDefElem("cache", (Node *)$2);
@@ -5342,17 +5435,19 @@ InsertStmt:
 		;
 
 insert_rest:
-			SelectStmt
+			OptOverride SelectStmt
 				{
 					$$ = makeNode(InsertStmt);
 					$$->cols = NIL;
-					$$->selectStmt = $1;
+					$$->override_def = $1;
+					$$->selectStmt = $2;
 				}
-			| '(' insert_column_list ')' SelectStmt
+			| '(' insert_column_list ')' OptOverride SelectStmt
 				{
 					$$ = makeNode(InsertStmt);
 					$$->cols = $2;
-					$$->selectStmt = $4;
+					$$->override_def = $4;
+					$$->selectStmt = $5;
 				}
 			| DEFAULT VALUES
 				{
@@ -5380,6 +5475,20 @@ insert_column_item:
 				}
 		;
 
+OptOverride:	OVERRIDING UserSystem VALUE
+				{
+					$$ = $2;
+				}
+			| /* EMPTY */
+				{
+					$$ = false;
+				}
+
+		;
+
+UserSystem:	SYSTEM_P						{ $$ = true; }
+			| USER						{ $$ = false; }
+		;
 
 /*****************************************************************************
  *
@@ -8461,6 +8570,7 @@ unreserved_keyword:
 			| AGGREGATE
 			| ALSO
 			| ALTER
+			| ALWAYS
 			| ASSERTION
 			| ASSIGNMENT
 			| AT
@@ -8520,6 +8630,7 @@ unreserved_keyword:
 			| FORCE
 			| FORWARD
 			| FUNCTION
+			| GENERATED
 			| GLOBAL
 			| GRANTED
 			| HANDLER
@@ -8578,6 +8689,7 @@ unreserved_keyword:
 			| OIDS
 			| OPERATOR
 			| OPTION
+			| OVERRIDING
 			| OWNED
 			| OWNER
 			| PARTIAL
@@ -8707,6 +8819,7 @@ col_name_keyword:
 			| TIMESTAMP
 			| TREAT
 			| TRIM
+			| VALUE
 			| VALUES
 			| VARCHAR
 		;
@@ -8788,6 +8901,7 @@ reserved_keyword:
 			| GRANT
 			| GROUP_P
 			| HAVING
+			| IDENTITY
 			| IN_P
 			| INITIALLY
 			| INTERSECT
diff -durpN pgsql.orig/src/backend/parser/keywords.c pgsql/src/backend/parser/keywords.c
--- pgsql.orig/src/backend/parser/keywords.c	2006-07-31 18:58:01.000000000 +0200
+++ pgsql/src/backend/parser/keywords.c	2006-08-09 17:20:20.000000000 +0200
@@ -42,6 +42,7 @@ static const ScanKeyword ScanKeywords[] 
 	{"all", ALL},
 	{"also", ALSO},
 	{"alter", ALTER},
+	{"always", ALWAYS},
 	{"analyse", ANALYSE},		/* British spelling */
 	{"analyze", ANALYZE},
 	{"and", AND},
@@ -151,6 +152,7 @@ static const ScanKeyword ScanKeywords[] 
 	{"from", FROM},
 	{"full", FULL},
 	{"function", FUNCTION},
+	{"generated", GENERATED},
 	{"global", GLOBAL},
 	{"grant", GRANT},
 	{"granted", GRANTED},
@@ -161,6 +163,7 @@ static const ScanKeyword ScanKeywords[] 
 	{"header", HEADER_P},
 	{"hold", HOLD},
 	{"hour", HOUR_P},
+	{"identity", IDENTITY},
 	{"if", IF_P},
 	{"ilike", ILIKE},
 	{"immediate", IMMEDIATE},
@@ -254,6 +257,7 @@ static const ScanKeyword ScanKeywords[] 
 	{"outer", OUTER_P},
 	{"overlaps", OVERLAPS},
 	{"overlay", OVERLAY},
+	{"overriding", OVERRIDING},
 	{"owned", OWNED},
 	{"owner", OWNER},
 	{"partial", PARTIAL},
@@ -354,6 +358,7 @@ static const ScanKeyword ScanKeywords[] 
 	{"vacuum", VACUUM},
 	{"valid", VALID},
 	{"validator", VALIDATOR},
+	{"value", VALUE},
 	{"values", VALUES},
 	{"varchar", VARCHAR},
 	{"varying", VARYING},
diff -durpN pgsql.orig/src/backend/rewrite/rewriteHandler.c pgsql/src/backend/rewrite/rewriteHandler.c
--- pgsql.orig/src/backend/rewrite/rewriteHandler.c	2006-08-03 10:37:50.000000000 +0200
+++ pgsql/src/backend/rewrite/rewriteHandler.c	2006-08-09 17:20:20.000000000 +0200
@@ -12,7 +12,7 @@
  *-------------------------------------------------------------------------
  */
 #include "postgres.h"
-
+#include "miscadmin.h"
 #include "access/heapam.h"
 #include "catalog/pg_type.h"
 #include "nodes/makefuncs.h"
@@ -23,6 +23,7 @@
 #include "parser/parsetree.h"
 #include "rewrite/rewriteHandler.h"
 #include "rewrite/rewriteManip.h"
+#include "utils/acl.h"
 #include "utils/builtins.h"
 #include "utils/lsyscache.h"
 
@@ -494,6 +495,7 @@ rewriteTargetList(Query *parsetree, Rela
 				  List **attrno_list)
 {
 	CmdType		commandType = parsetree->commandType;
+	bool		commandOverride = parsetree->commandOverride;
 	TargetEntry **new_tles;
 	List	   *new_tlist = NIL;
 	List	   *junk_tlist = NIL;
@@ -578,11 +580,27 @@ rewriteTargetList(Query *parsetree, Rela
 			continue;
 
 		/*
-		 * Handle the two cases where we need to insert a default expression:
-		 * it's an INSERT and there's no tlist entry for the column, or the
-		 * tlist entry is a DEFAULT placeholder node.
+		 * Handle the three cases where we need to insert a default expression:
+		 * - it's an INSERT and there's no tlist entry for the column, or
+		 * - it's an INSERT and the column is GENERATED ALWAYS
+		 * - the tlist entry is a DEFAULT placeholder node
+		 * Fail for UPDATE to non-default on GENERATED ALWAYS AS () columns.
+		 * Fail for UPDATE on GENERATED ALWAYS AS IDENTITY columns
+		 * Fail for INSERT into GENERATED ALWAYS column with OVERRIDING SYSTEM VALUE by a non-owner
 		 */
-		if ((new_tle == NULL && commandType == CMD_INSERT) ||
+		if (commandType == CMD_UPDATE && att_tup->atthasdef && att_tup->attforceddef &&
+			new_tle && new_tle->expr)
+		{
+			if (att_tup->attidentity)
+				elog(ERROR, "UPDATE prohibited on GENERATED ALWAYS AS IDENTITY attributes");
+			else if (!IsA(new_tle->expr, SetToDefault))
+				elog(ERROR, "UPDATE to non-default value prohibited on GENERATED ALWAYS attributes");
+		}
+		if (commandType == CMD_INSERT && att_tup->atthasdef && att_tup->attforceddef &&
+			commandOverride && !pg_class_ownercheck(RelationGetRelid(target_relation), GetUserId()))
+			aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,
+						RelationGetRelationName(target_relation));
+		if (((new_tle == NULL || (att_tup->atthasdef && att_tup->attforceddef && !commandOverride)) && commandType == CMD_INSERT) ||
 			(new_tle && new_tle->expr && IsA(new_tle->expr, SetToDefault)))
 		{
 			Node	   *new_expr;
diff -durpN pgsql.orig/src/backend/utils/adt/ruleutils.c pgsql/src/backend/utils/adt/ruleutils.c
--- pgsql.orig/src/backend/utils/adt/ruleutils.c	2006-08-03 10:37:50.000000000 +0200
+++ pgsql/src/backend/utils/adt/ruleutils.c	2006-08-09 17:20:20.000000000 +0200
@@ -1240,11 +1240,7 @@ pg_get_serial_sequence(PG_FUNCTION_ARGS)
 	Oid			tableOid;
 	char	   *column;
 	AttrNumber	attnum;
-	Oid			sequenceId = InvalidOid;
-	Relation	depRel;
-	ScanKeyData key[3];
-	SysScanDesc scan;
-	HeapTuple	tup;
+	Oid			sequenceId;
 
 	/* Get the OID of the table */
 	tablerv = makeRangeVarFromNameList(textToQualifiedNameList(tablename));
@@ -1255,50 +1251,7 @@ pg_get_serial_sequence(PG_FUNCTION_ARGS)
 											   PointerGetDatum(columnname)));
 
 	attnum = get_attnum(tableOid, column);
-	if (attnum == InvalidAttrNumber)
-		ereport(ERROR,
-				(errcode(ERRCODE_UNDEFINED_COLUMN),
-				 errmsg("column \"%s\" of relation \"%s\" does not exist",
-						column, tablerv->relname)));
-
-	/* Search the dependency table for the dependent sequence */
-	depRel = heap_open(DependRelationId, AccessShareLock);
-
-	ScanKeyInit(&key[0],
-				Anum_pg_depend_refclassid,
-				BTEqualStrategyNumber, F_OIDEQ,
-				ObjectIdGetDatum(RelationRelationId));
-	ScanKeyInit(&key[1],
-				Anum_pg_depend_refobjid,
-				BTEqualStrategyNumber, F_OIDEQ,
-				ObjectIdGetDatum(tableOid));
-	ScanKeyInit(&key[2],
-				Anum_pg_depend_refobjsubid,
-				BTEqualStrategyNumber, F_INT4EQ,
-				Int32GetDatum(attnum));
-
-	scan = systable_beginscan(depRel, DependReferenceIndexId, true,
-							  SnapshotNow, 3, key);
-
-	while (HeapTupleIsValid(tup = systable_getnext(scan)))
-	{
-		Form_pg_depend deprec = (Form_pg_depend) GETSTRUCT(tup);
-
-		/*
-		 * We assume any internal dependency of a relation on a column must be
-		 * what we are looking for.
-		 */
-		if (deprec->classid == RelationRelationId &&
-			deprec->objsubid == 0 &&
-			deprec->deptype == DEPENDENCY_INTERNAL)
-		{
-			sequenceId = deprec->objid;
-			break;
-		}
-	}
-
-	systable_endscan(scan);
-	heap_close(depRel, AccessShareLock);
+	sequenceId = get_relid_att_serial_sequence(tableOid, attnum);
 
 	if (OidIsValid(sequenceId))
 	{
diff -durpN pgsql.orig/src/backend/utils/cache/lsyscache.c pgsql/src/backend/utils/cache/lsyscache.c
--- pgsql.orig/src/backend/utils/cache/lsyscache.c	2006-07-29 23:44:28.000000000 +0200
+++ pgsql/src/backend/utils/cache/lsyscache.c	2006-08-09 17:20:20.000000000 +0200
@@ -15,9 +15,14 @@
  */
 #include "postgres.h"
 
+#include "access/genam.h"
 #include "access/hash.h"
+#include "access/heapam.h"
+#include "catalog/dependency.h"
+#include "catalog/indexing.h"
 #include "catalog/pg_amop.h"
 #include "catalog/pg_amproc.h"
+#include "catalog/pg_depend.h"
 #include "catalog/pg_namespace.h"
 #include "catalog/pg_opclass.h"
 #include "catalog/pg_operator.h"
@@ -28,6 +33,7 @@
 #include "utils/array.h"
 #include "utils/builtins.h"
 #include "utils/datum.h"
+#include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
 #include "utils/syscache.h"
 
@@ -354,6 +360,70 @@ get_relid_attribute_name(Oid relid, Attr
 }
 
 /*
+ * get_relid_attribute_sequence
+ *	Expose pg_get_serial_sequence() internally.
+ */
+Oid
+get_relid_att_serial_sequence(Oid relid, AttrNumber attnum)
+{
+	Oid		sequenceId = InvalidOid;
+	Relation	depRel;
+	ScanKeyData	key[3];
+	SysScanDesc	scan;
+	HeapTuple	tup;
+
+	if (attnum == InvalidAttrNumber)
+		ereport(ERROR,
+				(errcode(ERRCODE_UNDEFINED_COLUMN),
+				 errmsg("column \"%s\" of relation \"%s\" does not exist",
+				 get_relid_attribute_name(relid, attnum),
+				 get_rel_name(relid))));
+
+	/* Search the dependency table for the dependent sequence */
+	depRel = heap_open(DependRelationId, AccessShareLock);
+
+	ScanKeyInit(&key[0],
+				Anum_pg_depend_refclassid,
+				BTEqualStrategyNumber, F_OIDEQ,
+				ObjectIdGetDatum(RelationRelationId));
+
+	ScanKeyInit(&key[1],
+				Anum_pg_depend_refobjid,
+				BTEqualStrategyNumber, F_OIDEQ,
+				ObjectIdGetDatum(relid));
+
+	ScanKeyInit(&key[2],
+				Anum_pg_depend_refobjsubid,
+				BTEqualStrategyNumber, F_INT4EQ,
+				Int32GetDatum(attnum));
+
+	scan = systable_beginscan(depRel, DependReferenceIndexId, true,
+				SnapshotNow, 3, key);
+
+	while (HeapTupleIsValid(tup = systable_getnext(scan)))
+	{
+		Form_pg_depend deprec = (Form_pg_depend) GETSTRUCT(tup);
+		/*
+		 * We assume any internal dependency of a relation on a column must be
+		 * what we are looking for.
+		 */
+		if (deprec->classid == RelationRelationId &&
+			deprec->objsubid == 0 &&
+			deprec->deptype == DEPENDENCY_INTERNAL)
+		{
+			sequenceId = deprec->objid;
+			break;
+		}
+	}
+
+	systable_endscan(scan);
+
+	heap_close(depRel, AccessShareLock);
+	
+	return sequenceId;
+}
+
+/*
  * get_attnum
  *
  *		Given the relation id and the attribute name,
@@ -1207,7 +1277,6 @@ get_rel_relkind(Oid relid)
 		return '\0';
 }
 
-
 /*				---------- TYPE CACHE ----------						 */
 
 /*
diff -durpN pgsql.orig/src/bin/pg_dump/pg_dump.c pgsql/src/bin/pg_dump/pg_dump.c
--- pgsql.orig/src/bin/pg_dump/pg_dump.c	2006-08-05 16:46:50.000000000 +0200
+++ pgsql/src/bin/pg_dump/pg_dump.c	2006-08-09 17:20:20.000000000 +0200
@@ -149,7 +149,7 @@ static void dumpTrigger(Archive *fout, T
 static void dumpTable(Archive *fout, TableInfo *tbinfo);
 static void dumpTableSchema(Archive *fout, TableInfo *tbinfo);
 static void dumpAttrDef(Archive *fout, AttrDefInfo *adinfo);
-static void dumpSequence(Archive *fout, TableInfo *tbinfo);
+static void dumpSequence(Archive *fout, TableInfo *tbinfo, bool dumpfortable);
 static void dumpIndex(Archive *fout, IndxInfo *indxinfo);
 static void dumpConstraint(Archive *fout, ConstraintInfo *coninfo);
 static void dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo);
@@ -1248,6 +1248,8 @@ dumpTableData_insert(Archive *fout, void
 				appendPQExpBuffer(q, ") ");
 				archputs(q->data, fout);
 			}
+			if (tbinfo->hasforceddef)
+				archprintf(fout, "OVERRIDING SYSTEM VALUE ");
 			archprintf(fout, "VALUES (");
 			for (field = 0; field < nfields; field++)
 			{
@@ -1349,8 +1351,9 @@ dumpTableData(Archive *fout, TableDataIn
 		/* must use 2 steps here 'cause fmtId is nonreentrant */
 		appendPQExpBuffer(copyBuf, "COPY %s ",
 						  fmtId(tbinfo->dobj.name));
-		appendPQExpBuffer(copyBuf, "%s %sFROM stdin;\n",
+		appendPQExpBuffer(copyBuf, "%s %s%sFROM stdin;\n",
 						  fmtCopyColumnList(tbinfo),
+					  tbinfo->hasforceddef ? "OVERRIDING SYSTEM VALUE " : "",
 					  (tdinfo->oids && tbinfo->hasoids) ? "WITH OIDS " : "");
 		copyStmt = copyBuf->data;
 	}
@@ -4175,6 +4178,8 @@ getTableAttrs(TableInfo *tblinfo, int nu
 	int			i_atthasdef;
 	int			i_attisdropped;
 	int			i_attislocal;
+	int			i_attidentity;
+	int			i_attforceddef;
 	PGresult   *res;
 	int			ntups;
 	bool		hasdefaults;
@@ -4212,12 +4217,27 @@ getTableAttrs(TableInfo *tblinfo, int nu
 
 		resetPQExpBuffer(q);
 
-		if (g_fout->remoteVersion >= 70300)
+		if (g_fout->remoteVersion >= 80200)
 		{
 			/* need left join here to not fail on dropped columns ... */
 			appendPQExpBuffer(q, "SELECT a.attnum, a.attname, a.atttypmod, a.attstattarget, a.attstorage, t.typstorage, "
 				  "a.attnotnull, a.atthasdef, a.attisdropped, a.attislocal, "
-				   "pg_catalog.format_type(t.oid,a.atttypmod) as atttypname "
+				   "pg_catalog.format_type(t.oid,a.atttypmod) as atttypname, "
+				   "a.attidentity, a.attforceddef "
+			 "from pg_catalog.pg_attribute a left join pg_catalog.pg_type t "
+							  "on a.atttypid = t.oid "
+							  "where a.attrelid = '%u'::pg_catalog.oid "
+							  "and a.attnum > 0::pg_catalog.int2 "
+							  "order by a.attrelid, a.attnum",
+							  tbinfo->dobj.catId.oid);
+		}
+		else if (g_fout->remoteVersion >= 70300)
+		{
+			/* need left join here to not fail on dropped columns ... */
+			appendPQExpBuffer(q, "SELECT a.attnum, a.attname, a.atttypmod, a.attstattarget, a.attstorage, t.typstorage, "
+				  "a.attnotnull, a.atthasdef, a.attisdropped, a.attislocal, "
+				   "pg_catalog.format_type(t.oid,a.atttypmod) as atttypname, "
+				   "false as attidentity, false as attforceddef "
 			 "from pg_catalog.pg_attribute a left join pg_catalog.pg_type t "
 							  "on a.atttypid = t.oid "
 							  "where a.attrelid = '%u'::pg_catalog.oid "
@@ -4234,7 +4254,8 @@ getTableAttrs(TableInfo *tblinfo, int nu
 			 */
 			appendPQExpBuffer(q, "SELECT a.attnum, a.attname, a.atttypmod, -1 as attstattarget, a.attstorage, t.typstorage, "
 							  "a.attnotnull, a.atthasdef, false as attisdropped, false as attislocal, "
-							  "format_type(t.oid,a.atttypmod) as atttypname "
+							  "format_type(t.oid,a.atttypmod) as atttypname, "
+							  "false as attidentity, false as attforceddef "
 							  "from pg_attribute a left join pg_type t "
 							  "on a.atttypid = t.oid "
 							  "where a.attrelid = '%u'::oid "
@@ -4247,7 +4268,8 @@ getTableAttrs(TableInfo *tblinfo, int nu
 			/* format_type not available before 7.1 */
 			appendPQExpBuffer(q, "SELECT attnum, attname, atttypmod, -1 as attstattarget, attstorage, attstorage as typstorage, "
 							  "attnotnull, atthasdef, false as attisdropped, false as attislocal, "
-							  "(select typname from pg_type where oid = atttypid) as atttypname "
+							  "(select typname from pg_type where oid = atttypid) as atttypname, "
+							  "false as attidentity, false as attforceddef "
 							  "from pg_attribute a "
 							  "where attrelid = '%u'::oid "
 							  "and attnum > 0::int2 "
@@ -4271,6 +4293,8 @@ getTableAttrs(TableInfo *tblinfo, int nu
 		i_atthasdef = PQfnumber(res, "atthasdef");
 		i_attisdropped = PQfnumber(res, "attisdropped");
 		i_attislocal = PQfnumber(res, "attislocal");
+		i_attidentity = PQfnumber(res, "attidentity");
+		i_attforceddef = PQfnumber(res, "attforceddef");
 
 		tbinfo->numatts = ntups;
 		tbinfo->attnames = (char **) malloc(ntups * sizeof(char *));
@@ -4281,7 +4305,10 @@ getTableAttrs(TableInfo *tblinfo, int nu
 		tbinfo->typstorage = (char *) malloc(ntups * sizeof(char));
 		tbinfo->attisdropped = (bool *) malloc(ntups * sizeof(bool));
 		tbinfo->attislocal = (bool *) malloc(ntups * sizeof(bool));
-		tbinfo->attisserial = (bool *) malloc(ntups * sizeof(bool));
+		tbinfo->attidentity = (bool *) malloc(ntups * sizeof(bool));
+		tbinfo->dependant_seq = (Oid *) malloc(ntups * sizeof(Oid));
+		tbinfo->attforceddef = (bool *) malloc(ntups * sizeof(bool));
+		tbinfo->seqopts = (PQExpBuffer *) malloc(ntups * sizeof(PQExpBuffer));
 		tbinfo->notnull = (bool *) malloc(ntups * sizeof(bool));
 		tbinfo->attrdefs = (AttrDefInfo **) malloc(ntups * sizeof(AttrDefInfo *));
 		tbinfo->inhAttrs = (bool *) malloc(ntups * sizeof(bool));
@@ -4305,7 +4332,10 @@ getTableAttrs(TableInfo *tblinfo, int nu
 			tbinfo->typstorage[j] = *(PQgetvalue(res, j, i_typstorage));
 			tbinfo->attisdropped[j] = (PQgetvalue(res, j, i_attisdropped)[0] == 't');
 			tbinfo->attislocal[j] = (PQgetvalue(res, j, i_attislocal)[0] == 't');
-			tbinfo->attisserial[j] = false;		/* fix below */
+			tbinfo->attidentity[j] = (PQgetvalue(res, j, i_attidentity)[0] == 't'); /* patch below for version < 8.2 */
+			tbinfo->dependant_seq[j] = InvalidOid;
+			tbinfo->attforceddef[j] = (PQgetvalue(res, j, i_attforceddef)[0] == 't');
+			tbinfo->hasforceddef |= tbinfo->attforceddef[j];
 			tbinfo->notnull[j] = (PQgetvalue(res, j, i_attnotnull)[0] == 't');
 			tbinfo->attrdefs[j] = NULL; /* fix below */
 			if (PQgetvalue(res, j, i_atthasdef)[0] == 't')
@@ -4551,9 +4581,15 @@ getTableAttrs(TableInfo *tblinfo, int nu
 			 * Note assumption that format_type will show these types as
 			 * exactly "integer" and "bigint" regardless of schema path. This
 			 * is correct in 7.3 but needs to be watched.
+			 * 8.2 or above has indication about IDENTITY columns.
 			 */
-			if (strcmp(tbinfo->atttypnames[j], "integer") != 0 &&
-				strcmp(tbinfo->atttypnames[j], "bigint") != 0)
+			if (g_fout->remoteVersion >= 80200)
+			{
+				if (!tbinfo->attidentity[j])
+					continue;
+			}
+			else if (strcmp(tbinfo->atttypnames[j], "integer") != 0 &&
+					strcmp(tbinfo->atttypnames[j], "bigint") != 0)
 				continue;
 			if (tbinfo->attrdefs[j] == NULL)
 				continue;
@@ -4569,7 +4605,8 @@ getTableAttrs(TableInfo *tblinfo, int nu
 					 * Found a match.  Copy the table's interesting and
 					 * dumpable flags to the sequence.
 					 */
-					tbinfo->attisserial[j] = true;
+					tbinfo->attidentity[j] = true; /* This is needed for version < 8.2 */
+					tbinfo->dependant_seq[j] = seqinfo->dobj.catId.oid;
 					seqinfo->interesting = tbinfo->interesting;
 					seqinfo->dobj.dump = tbinfo->dobj.dump;
 					break;
@@ -7271,9 +7308,31 @@ dumpTable(Archive *fout, TableInfo *tbin
 	if (tbinfo->dobj.dump)
 	{
 		if (tbinfo->relkind == RELKIND_SEQUENCE)
-			dumpSequence(fout, tbinfo);
+			dumpSequence(fout, tbinfo, false);
 		else if (!dataOnly)
+		{
+			int	k;
+			for (k = 0; k < tbinfo->numatts; k++)
+			{
+				if (tbinfo->attidentity[k] &&
+					tbinfo->dependant_seq[k] != InvalidOid)
+				{
+					TableInfo  *seqinfo = findTableByOid(tbinfo->dependant_seq[k]);
+
+					if (OidIsValid(seqinfo->owning_tab) &&
+						seqinfo->owning_tab == tbinfo->dobj.catId.oid &&
+						seqinfo->owning_col == k + 1)
+					{
+						/*
+						 * Found a match.  Fill the tbinfo's seqopts.
+						 */
+						dumpSequence(fout, seqinfo, true);
+						break;
+					}
+				}
+			}
 			dumpTableSchema(fout, tbinfo);
+		}
 
 		/* Handle the ACL here */
 		namecopy = strdup(fmtId(tbinfo->dobj.name));
@@ -7405,7 +7464,7 @@ dumpTableSchema(Archive *fout, TableInfo
 				{
 					char	   *typname = tbinfo->atttypnames[j];
 
-					if (tbinfo->attisserial[j])
+					if (tbinfo->attidentity[j])
 					{
 						if (strcmp(typname, "integer") == 0)
 							typname = "serial";
@@ -7423,15 +7482,31 @@ dumpTableSchema(Archive *fout, TableInfo
 				}
 
 				/*
-				 * Default value --- suppress if inherited, serial, or to be
+				 * Default value --- suppress if inherited, or to be
 				 * printed separately.
 				 */
 				if (tbinfo->attrdefs[j] != NULL &&
 					!tbinfo->inhAttrDef[j] &&
-					!tbinfo->attisserial[j] &&
+					!tbinfo->attidentity[j] &&
 					!tbinfo->attrdefs[j]->separate)
-					appendPQExpBuffer(q, " DEFAULT %s",
+				{
+					if (tbinfo->attforceddef[j])
+						appendPQExpBuffer(q, " GENERATED ALWAYS AS ( %s )",
+									  tbinfo->attrdefs[j]->adef_expr);
+					else
+						appendPQExpBuffer(q, " DEFAULT %s",
 									  tbinfo->attrdefs[j]->adef_expr);
+				}
+				if (tbinfo->attidentity[j])
+				{
+					if (tbinfo->attforceddef[j])
+						appendPQExpBuffer(q, " GENERATED ALWAYS AS IDENTITY ( %s )",
+								  tbinfo->seqopts[j]->data);
+					else
+						appendPQExpBuffer(q, " GENERATED BY DEFAULT AS IDENTITY ( %s )",
+								  tbinfo->seqopts[j]->data);
+					destroyPQExpBuffer(tbinfo->seqopts[j]);
+				}
 
 				/*
 				 * Not Null constraint --- suppress if inherited
@@ -7598,7 +7673,7 @@ dumpAttrDef(Archive *fout, AttrDefInfo *
 		return;
 
 	/* Don't print inherited or serial defaults, either */
-	if (tbinfo->inhAttrDef[adnum - 1] || tbinfo->attisserial[adnum - 1])
+	if (tbinfo->inhAttrDef[adnum - 1] || tbinfo->attidentity[adnum - 1])
 		return;
 
 	q = createPQExpBuffer();
@@ -8043,7 +8118,7 @@ findLastBuiltinOid_V70(void)
 }
 
 static void
-dumpSequence(Archive *fout, TableInfo *tbinfo)
+dumpSequence(Archive *fout, TableInfo *tbinfo, bool preparefortable)
 {
 	PGresult   *res;
 	char	   *last,
@@ -8057,6 +8132,7 @@ dumpSequence(Archive *fout, TableInfo *t
 				called;
 	PQExpBuffer query = createPQExpBuffer();
 	PQExpBuffer delqry = createPQExpBuffer();
+	PQExpBuffer seqopts = createPQExpBuffer();
 
 	/* Make sure we are in proper schema */
 	selectSourceSchema(tbinfo->dobj.namespace->dobj.name);
@@ -8119,46 +8195,52 @@ dumpSequence(Archive *fout, TableInfo *t
 	 * data. We do this for serial sequences too.
 	 */
 
-	if (!dataOnly && !OidIsValid(tbinfo->owning_tab))
+	if (!dataOnly)
 	{
-		resetPQExpBuffer(delqry);
+		resetPQExpBuffer(query);
+		if (!OidIsValid(tbinfo->owning_tab))
+		{
+			resetPQExpBuffer(delqry);
 
-		/*
-		 * DROP must be fully qualified in case same name appears in
-		 * pg_catalog
-		 */
-		appendPQExpBuffer(delqry, "DROP SEQUENCE %s.",
-						  fmtId(tbinfo->dobj.namespace->dobj.name));
-		appendPQExpBuffer(delqry, "%s;\n",
-						  fmtId(tbinfo->dobj.name));
+			/*
+			 * DROP must be fully qualified in case same name appears in
+			 * pg_catalog
+			 */
+			appendPQExpBuffer(delqry, "DROP SEQUENCE %s.",
+							  fmtId(tbinfo->dobj.namespace->dobj.name));
+			appendPQExpBuffer(delqry, "%s;\n",
+							  fmtId(tbinfo->dobj.name));
 
-		resetPQExpBuffer(query);
-		appendPQExpBuffer(query,
+			appendPQExpBuffer(query,
 						  "CREATE SEQUENCE %s\n",
 						  fmtId(tbinfo->dobj.name));
+		}
 
 		if (!called)
-			appendPQExpBuffer(query, "    START WITH %s\n", last);
+			appendPQExpBuffer(seqopts, "    START WITH %s\n", last);
 
-		appendPQExpBuffer(query, "    INCREMENT BY %s\n", incby);
+		appendPQExpBuffer(seqopts, "    INCREMENT BY %s\n", incby);
 
 		if (maxv)
-			appendPQExpBuffer(query, "    MAXVALUE %s\n", maxv);
+			appendPQExpBuffer(seqopts, "    MAXVALUE %s\n", maxv);
 		else
-			appendPQExpBuffer(query, "    NO MAXVALUE\n");
+			appendPQExpBuffer(seqopts, "    NO MAXVALUE\n");
 
 		if (minv)
-			appendPQExpBuffer(query, "    MINVALUE %s\n", minv);
+			appendPQExpBuffer(seqopts, "    MINVALUE %s\n", minv);
 		else
-			appendPQExpBuffer(query, "    NO MINVALUE\n");
+			appendPQExpBuffer(seqopts, "    NO MINVALUE\n");
 
-		appendPQExpBuffer(query,
+		appendPQExpBuffer(seqopts,
 						  "    CACHE %s%s",
 						  cache, (cycled ? "\n    CYCLE" : ""));
 
-		appendPQExpBuffer(query, ";\n");
+		if (!OidIsValid(tbinfo->owning_tab))
+		{
+			appendPQExpBuffer(query, "%s;\n", seqopts->data);
+			destroyPQExpBuffer(seqopts);
 
-		ArchiveEntry(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId,
+			ArchiveEntry(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId,
 					 tbinfo->dobj.name,
 					 tbinfo->dobj.namespace->dobj.name,
 					 NULL,
@@ -8166,6 +8248,13 @@ dumpSequence(Archive *fout, TableInfo *t
 					 false, "SEQUENCE", query->data, delqry->data, NULL,
 					 tbinfo->dobj.dependencies, tbinfo->dobj.nDeps,
 					 NULL, NULL);
+		}
+		else
+		{
+			TableInfo	*owning_tab = findTableByOid(tbinfo->owning_tab);
+			owning_tab->seqopts[tbinfo->owning_col - 1] = seqopts;
+			/* seqopts will be destroyed by dumpTableSchema */
+		}
 	}
 
 	if (!schemaOnly)
@@ -8173,29 +8262,38 @@ dumpSequence(Archive *fout, TableInfo *t
 		TableInfo  *owning_tab;
 
 		resetPQExpBuffer(query);
-		appendPQExpBuffer(query, "SELECT pg_catalog.setval(");
-
 		/*
-		 * If this is a SERIAL sequence, then use the pg_get_serial_sequence
-		 * function to avoid hard-coding the sequence name.  Note that this
-		 * implicitly assumes that the sequence and its owning table are in
-		 * the same schema, because we don't schema-qualify the reference.
+		 * If this is a SERIAL sequence, then dump
+		 * ALTER TABLE tab ALTER col RESTART WITH N.
 		 */
 		if (OidIsValid(tbinfo->owning_tab) &&
 			(owning_tab = findTableByOid(tbinfo->owning_tab)) != NULL)
 		{
-			appendPQExpBuffer(query, "pg_catalog.pg_get_serial_sequence(");
-			appendStringLiteralAH(query, fmtId(owning_tab->dobj.name), fout);
-			appendPQExpBuffer(query, ", ");
-			appendStringLiteralAH(query, owning_tab->attnames[tbinfo->owning_col - 1], fout);
-			appendPQExpBuffer(query, ")");
+			long long	lastval;
+			if (called && !preparefortable)
+			{
+				sscanf(last, "%lld", &lastval);
+				appendPQExpBuffer(query, "ALTER TABLE %s ALTER %s SET RESTART WITH %lld;\n",
+					fmtId(owning_tab->dobj.name),
+					owning_tab->attnames[tbinfo->owning_col - 1],
+					lastval + 1);
+				ArchiveEntry(fout, nilCatalogId, createDumpId(),
+					 tbinfo->dobj.name,
+					 tbinfo->dobj.namespace->dobj.name,
+					 NULL,
+					 tbinfo->rolname,
+					 false, "SEQUENCE SET", query->data, "", NULL,
+					 &(tbinfo->dobj.dumpId), 1,
+					 NULL, NULL);
+			}
 		}
 		else
+		{
+			appendPQExpBuffer(query, "SELECT pg_catalog.setval(");
 			appendStringLiteralAH(query, fmtId(tbinfo->dobj.name), fout);
-		appendPQExpBuffer(query, ", %s, %s);\n",
+			appendPQExpBuffer(query, ", %s, %s);\n",
 						  last, (called ? "true" : "false"));
-
-		ArchiveEntry(fout, nilCatalogId, createDumpId(),
+			ArchiveEntry(fout, nilCatalogId, createDumpId(),
 					 tbinfo->dobj.name,
 					 tbinfo->dobj.namespace->dobj.name,
 					 NULL,
@@ -8203,6 +8301,7 @@ dumpSequence(Archive *fout, TableInfo *t
 					 false, "SEQUENCE SET", query->data, "", NULL,
 					 &(tbinfo->dobj.dumpId), 1,
 					 NULL, NULL);
+		}
 	}
 
 	if (!dataOnly)
diff -durpN pgsql.orig/src/bin/pg_dump/pg_dump.h pgsql/src/bin/pg_dump/pg_dump.h
--- pgsql.orig/src/bin/pg_dump/pg_dump.h	2006-08-01 22:19:01.000000000 +0200
+++ pgsql/src/bin/pg_dump/pg_dump.h	2006-08-09 17:20:20.000000000 +0200
@@ -15,6 +15,7 @@
 #define PG_DUMP_H
 
 #include "postgres_fe.h"
+#include "pqexpbuffer.h"
 
 
 /*
@@ -204,7 +205,11 @@ typedef struct _tableInfo
 	char	   *typstorage;		/* type storage scheme */
 	bool	   *attisdropped;	/* true if attr is dropped; don't dump it */
 	bool	   *attislocal;		/* true if attr has local definition */
-	bool	   *attisserial;	/* true if attr is serial or bigserial */
+	bool	   *attidentity;	/* true if attr is GENERATED AS IDENTITY or [big]serial */
+	Oid	   *dependant_seq;	/* Oid of SEQUENCE this IDENTITY column depends on */
+	bool	   *attforceddef;	/* true if attr is GENERATED ALWAYS */
+	bool	    hasforceddef;	/* true if any of the attrs is GENERATED ALWAYS */
+	PQExpBuffer *seqopts;		/* SEQUENCE options for IDENTITY columns */
 
 	/*
 	 * Note: we need to store per-attribute notnull, default, and constraint
diff -durpN pgsql.orig/src/include/catalog/heap.h pgsql/src/include/catalog/heap.h
--- pgsql.orig/src/include/catalog/heap.h	2006-07-14 13:52:03.000000000 +0200
+++ pgsql/src/include/catalog/heap.h	2006-08-09 17:20:20.000000000 +0200
@@ -21,6 +21,8 @@ typedef struct RawColumnDefault
 {
 	AttrNumber	attnum;			/* attribute to attach default to */
 	Node	   *raw_default;	/* default value (untransformed parse tree) */
+	bool		is_identity;		/* column is GENERATED AS IDENTITY */
+	bool		force_default;		/* column is GENERATED ALWAYS */
 } RawColumnDefault;
 
 typedef struct CookedConstraint
@@ -29,6 +31,7 @@ typedef struct CookedConstraint
 	char	   *name;			/* name, or NULL if none */
 	AttrNumber	attnum;			/* which attr (only for DEFAULT) */
 	Node	   *expr;			/* transformed default or check expr */
+	bool		force_default;		/* GENERATED ALWAYS */
 } CookedConstraint;
 
 extern Relation heap_create(const char *relname,
@@ -71,7 +74,7 @@ extern List *AddRelationRawConstraints(R
 						  List *rawColDefaults,
 						  List *rawConstraints);
 
-extern void StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin);
+extern void StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin, bool attidentity, bool attforceddef);
 
 extern Node *cookDefault(ParseState *pstate,
 			Node *raw_default,
diff -durpN pgsql.orig/src/include/catalog/pg_attribute.h pgsql/src/include/catalog/pg_attribute.h
--- pgsql.orig/src/include/catalog/pg_attribute.h	2006-07-11 16:09:46.000000000 +0200
+++ pgsql/src/include/catalog/pg_attribute.h	2006-08-09 17:20:20.000000000 +0200
@@ -149,6 +149,12 @@ CATALOG(pg_attribute,1249) BKI_BOOTSTRAP
 
 	/* Number of times inherited from direct parent relation(s) */
 	int4		attinhcount;
+
+	/* GENERATED ... AS IDENTITY or SERIAL */
+	bool		attidentity;
+
+	/* GENERATED ALWAYS */
+	bool		attforceddef;
 } FormData_pg_attribute;
 
 /*
@@ -157,7 +163,7 @@ CATALOG(pg_attribute,1249) BKI_BOOTSTRAP
  * because of alignment padding at the end of the struct.)
  */
 #define ATTRIBUTE_TUPLE_SIZE \
-	(offsetof(FormData_pg_attribute,attinhcount) + sizeof(int4))
+	(offsetof(FormData_pg_attribute,attforceddef) + sizeof(bool))
 
 /* ----------------
  *		Form_pg_attribute corresponds to a pointer to a tuple with
@@ -171,7 +177,7 @@ typedef FormData_pg_attribute *Form_pg_a
  * ----------------
  */
 
-#define Natts_pg_attribute				17
+#define Natts_pg_attribute				19
 #define Anum_pg_attribute_attrelid		1
 #define Anum_pg_attribute_attname		2
 #define Anum_pg_attribute_atttypid		3
@@ -189,6 +195,8 @@ typedef FormData_pg_attribute *Form_pg_a
 #define Anum_pg_attribute_attisdropped	15
 #define Anum_pg_attribute_attislocal	16
 #define Anum_pg_attribute_attinhcount	17
+#define Anum_pg_attribute_attidentity	18
+#define Anum_pg_attribute_attforceddef	19
 
 
 
@@ -222,228 +230,233 @@ typedef FormData_pg_attribute *Form_pg_a
  * ----------------
  */
 #define Schema_pg_type \
-{ 1247, {"typname"},	   19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'i', true, false, false, true, 0 }, \
-{ 1247, {"typnamespace"},  26, -1,	4,	2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1247, {"typowner"},	   26, -1,	4,	3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1247, {"typlen"},		   21, -1,	2,	4, 0, -1, -1, true, 'p', 's', true, false, false, true, 0 }, \
-{ 1247, {"typbyval"},	   16, -1,	1,	5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1247, {"typtype"},	   18, -1,	1,	6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1247, {"typisdefined"},  16, -1,	1,	7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1247, {"typdelim"},	   18, -1,	1,	8, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1247, {"typrelid"},	   26, -1,	4,	9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1247, {"typelem"},	   26, -1,	4, 10, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1247, {"typinput"},	   24, -1,	4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1247, {"typoutput"},	   24, -1,	4, 12, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1247, {"typreceive"},    24, -1,	4, 13, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1247, {"typsend"},	   24, -1,	4, 14, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1247, {"typanalyze"},    24, -1,	4, 15, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1247, {"typalign"},	   18, -1,	1, 16, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1247, {"typstorage"},    18, -1,	1, 17, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1247, {"typnotnull"},    16, -1,	1, 18, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1247, {"typbasetype"},   26, -1,	4, 19, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1247, {"typtypmod"},	   23, -1,	4, 20, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1247, {"typndims"},	   23, -1,	4, 21, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1247, {"typdefaultbin"}, 25, -1, -1, 22, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0 }, \
-{ 1247, {"typdefault"},    25, -1, -1, 23, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0 }
+{ 1247, {"typname"},	   19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1247, {"typnamespace"},  26, -1,	4,	2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1247, {"typowner"},	   26, -1,	4,	3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1247, {"typlen"},		   21, -1,	2,	4, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, false, false }, \
+{ 1247, {"typbyval"},	   16, -1,	1,	5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1247, {"typtype"},	   18, -1,	1,	6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1247, {"typisdefined"},  16, -1,	1,	7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1247, {"typdelim"},	   18, -1,	1,	8, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1247, {"typrelid"},	   26, -1,	4,	9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1247, {"typelem"},	   26, -1,	4, 10, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1247, {"typinput"},	   24, -1,	4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1247, {"typoutput"},	   24, -1,	4, 12, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1247, {"typreceive"},    24, -1,	4, 13, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1247, {"typsend"},	   24, -1,	4, 14, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1247, {"typanalyze"},    24, -1,	4, 15, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1247, {"typalign"},	   18, -1,	1, 16, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1247, {"typstorage"},    18, -1,	1, 17, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1247, {"typnotnull"},    16, -1,	1, 18, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1247, {"typbasetype"},   26, -1,	4, 19, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1247, {"typtypmod"},	   23, -1,	4, 20, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1247, {"typndims"},	   23, -1,	4, 21, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1247, {"typdefaultbin"}, 25, -1, -1, 22, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, false, false }, \
+{ 1247, {"typdefault"},    25, -1, -1, 23, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, false, false }
 
-DATA(insert ( 1247 typname			19 -1 NAMEDATALEN	1 0 -1 -1 f p i t f f t 0));
-DATA(insert ( 1247 typnamespace		26 -1 4   2 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1247 typowner			26 -1 4   3 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1247 typlen			21 -1 2   4 0 -1 -1 t p s t f f t 0));
-DATA(insert ( 1247 typbyval			16 -1 1   5 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1247 typtype			18 -1 1   6 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1247 typisdefined		16 -1 1   7 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1247 typdelim			18 -1 1   8 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1247 typrelid			26 -1 4   9 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1247 typelem			26 -1 4  10 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1247 typinput			24 -1 4  11 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1247 typoutput		24 -1 4  12 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1247 typreceive		24 -1 4  13 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1247 typsend			24 -1 4  14 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1247 typanalyze		24 -1 4  15 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1247 typalign			18 -1 1  16 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1247 typstorage		18 -1 1  17 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1247 typnotnull		16 -1 1  18 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1247 typbasetype		26 -1 4  19 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1247 typtypmod		23 -1 4  20 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1247 typndims			23 -1 4  21 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1247 typdefaultbin	25 -1 -1 22 0 -1 -1 f x i f f f t 0));
-DATA(insert ( 1247 typdefault		25 -1 -1 23 0 -1 -1 f x i f f f t 0));
-DATA(insert ( 1247 ctid				27 0  6  -1 0 -1 -1 f p s t f f t 0));
-DATA(insert ( 1247 oid				26 0  4  -2 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1247 xmin				28 0  4  -3 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1247 cmin				29 0  4  -4 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1247 xmax				28 0  4  -5 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1247 cmax				29 0  4  -6 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1247 tableoid			26 0  4  -7 0 -1 -1 t p i t f f t 0));
+DATA(insert ( 1247 typname			19 -1 NAMEDATALEN	1 0 -1 -1 f p i t f f t 0 f f));
+DATA(insert ( 1247 typnamespace		26 -1 4   2 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1247 typowner			26 -1 4   3 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1247 typlen			21 -1 2   4 0 -1 -1 t p s t f f t 0 f f));
+DATA(insert ( 1247 typbyval			16 -1 1   5 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1247 typtype			18 -1 1   6 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1247 typisdefined		16 -1 1   7 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1247 typdelim			18 -1 1   8 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1247 typrelid			26 -1 4   9 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1247 typelem			26 -1 4  10 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1247 typinput			24 -1 4  11 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1247 typoutput		24 -1 4  12 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1247 typreceive		24 -1 4  13 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1247 typsend			24 -1 4  14 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1247 typanalyze		24 -1 4  15 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1247 typalign			18 -1 1  16 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1247 typstorage		18 -1 1  17 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1247 typnotnull		16 -1 1  18 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1247 typbasetype		26 -1 4  19 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1247 typtypmod		23 -1 4  20 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1247 typndims			23 -1 4  21 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1247 typdefaultbin	25 -1 -1 22 0 -1 -1 f x i f f f t 0 f f));
+DATA(insert ( 1247 typdefault		25 -1 -1 23 0 -1 -1 f x i f f f t 0 f f));
+DATA(insert ( 1247 ctid				27 0  6  -1 0 -1 -1 f p s t f f t 0 f f));
+DATA(insert ( 1247 oid				26 0  4  -2 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1247 xmin				28 0  4  -3 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1247 cmin				29 0  4  -4 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1247 xmax				28 0  4  -5 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1247 cmax				29 0  4  -6 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1247 tableoid			26 0  4  -7 0 -1 -1 t p i t f f t 0 f f));
 
 /* ----------------
  *		pg_proc
  * ----------------
  */
 #define Schema_pg_proc \
-{ 1255, {"proname"},			19, -1, NAMEDATALEN,  1, 0, -1, -1, false, 'p', 'i', true, false, false, true, 0 }, \
-{ 1255, {"pronamespace"},		26, -1, 4,	2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1255, {"proowner"},			26, -1, 4,	3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1255, {"prolang"},			26, -1, 4,	4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1255, {"proisagg"},			16, -1, 1,	5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1255, {"prosecdef"},			16, -1, 1,	6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1255, {"proisstrict"},		16, -1, 1,	7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1255, {"proretset"},			16, -1, 1,	8, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1255, {"provolatile"},		18, -1, 1,	9, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1255, {"pronargs"},			21, -1, 2, 10, 0, -1, -1, true, 'p', 's', true, false, false, true, 0 }, \
-{ 1255, {"prorettype"},			26, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1255, {"proargtypes"},		30, -1, -1, 12, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0 }, \
-{ 1255, {"proallargtypes"},   1028, -1, -1, 13, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0 }, \
-{ 1255, {"proargmodes"},	  1002, -1, -1, 14, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0 }, \
-{ 1255, {"proargnames"},	  1009, -1, -1, 15, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0 }, \
-{ 1255, {"prosrc"},				25, -1, -1, 16, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0 }, \
-{ 1255, {"probin"},				17, -1, -1, 17, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0 }, \
-{ 1255, {"proacl"},			  1034, -1, -1, 18, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0 }
+{ 1255, {"proname"},			19, -1, NAMEDATALEN,  1, 0, -1, -1, false, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1255, {"pronamespace"},		26, -1, 4,	2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1255, {"proowner"},			26, -1, 4,	3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1255, {"prolang"},			26, -1, 4,	4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1255, {"proisagg"},			16, -1, 1,	5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1255, {"prosecdef"},			16, -1, 1,	6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1255, {"proisstrict"},		16, -1, 1,	7, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1255, {"proretset"},			16, -1, 1,	8, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1255, {"provolatile"},		18, -1, 1,	9, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1255, {"pronargs"},			21, -1, 2, 10, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, false, false }, \
+{ 1255, {"prorettype"},			26, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1255, {"proargtypes"},		30, -1, -1, 12, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1255, {"proallargtypes"},   1028, -1, -1, 13, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, false, false }, \
+{ 1255, {"proargmodes"},	  1002, -1, -1, 14, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, false, false }, \
+{ 1255, {"proargnames"},	  1009, -1, -1, 15, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, false, false }, \
+{ 1255, {"prosrc"},				25, -1, -1, 16, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, false, false }, \
+{ 1255, {"probin"},				17, -1, -1, 17, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, false, false }, \
+{ 1255, {"proacl"},			  1034, -1, -1, 18, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, false, false }
 
-DATA(insert ( 1255 proname			19 -1 NAMEDATALEN	1 0 -1 -1 f p i t f f t 0));
-DATA(insert ( 1255 pronamespace		26 -1 4   2 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1255 proowner			26 -1 4   3 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1255 prolang			26 -1 4   4 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1255 proisagg			16 -1 1   5 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1255 prosecdef		16 -1 1   6 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1255 proisstrict		16 -1 1   7 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1255 proretset		16 -1 1   8 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1255 provolatile		18 -1 1   9 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1255 pronargs			21 -1 2  10 0 -1 -1 t p s t f f t 0));
-DATA(insert ( 1255 prorettype		26 -1 4  11 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1255 proargtypes		30 -1 -1 12 1 -1 -1 f p i t f f t 0));
-DATA(insert ( 1255 proallargtypes 1028 -1 -1 13 1 -1 -1 f x i f f f t 0));
-DATA(insert ( 1255 proargmodes	  1002 -1 -1 14 1 -1 -1 f x i f f f t 0));
-DATA(insert ( 1255 proargnames	  1009 -1 -1 15 1 -1 -1 f x i f f f t 0));
-DATA(insert ( 1255 prosrc			25 -1 -1 16 0 -1 -1 f x i f f f t 0));
-DATA(insert ( 1255 probin			17 -1 -1 17 0 -1 -1 f x i f f f t 0));
-DATA(insert ( 1255 proacl		  1034 -1 -1 18 1 -1 -1 f x i f f f t 0));
-DATA(insert ( 1255 ctid				27 0  6  -1 0 -1 -1 f p s t f f t 0));
-DATA(insert ( 1255 oid				26 0  4  -2 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1255 xmin				28 0  4  -3 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1255 cmin				29 0  4  -4 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1255 xmax				28 0  4  -5 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1255 cmax				29 0  4  -6 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1255 tableoid			26 0  4  -7 0 -1 -1 t p i t f f t 0));
+DATA(insert ( 1255 proname			19 -1 NAMEDATALEN	1 0 -1 -1 f p i t f f t 0 f f));
+DATA(insert ( 1255 pronamespace		26 -1 4   2 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1255 proowner			26 -1 4   3 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1255 prolang			26 -1 4   4 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1255 proisagg			16 -1 1   5 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1255 prosecdef		16 -1 1   6 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1255 proisstrict		16 -1 1   7 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1255 proretset		16 -1 1   8 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1255 provolatile		18 -1 1   9 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1255 pronargs			21 -1 2  10 0 -1 -1 t p s t f f t 0 f f));
+DATA(insert ( 1255 prorettype		26 -1 4  11 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1255 proargtypes		30 -1 -1 12 1 -1 -1 f p i t f f t 0 f f));
+DATA(insert ( 1255 proallargtypes 1028 -1 -1 13 1 -1 -1 f x i f f f t 0 f f));
+DATA(insert ( 1255 proargmodes	  1002 -1 -1 14 1 -1 -1 f x i f f f t 0 f f));
+DATA(insert ( 1255 proargnames	  1009 -1 -1 15 1 -1 -1 f x i f f f t 0 f f));
+DATA(insert ( 1255 prosrc			25 -1 -1 16 0 -1 -1 f x i f f f t 0 f f));
+DATA(insert ( 1255 probin			17 -1 -1 17 0 -1 -1 f x i f f f t 0 f f));
+DATA(insert ( 1255 proacl		  1034 -1 -1 18 1 -1 -1 f x i f f f t 0 f f));
+DATA(insert ( 1255 ctid				27 0  6  -1 0 -1 -1 f p s t f f t 0 f f));
+DATA(insert ( 1255 oid				26 0  4  -2 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1255 xmin				28 0  4  -3 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1255 cmin				29 0  4  -4 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1255 xmax				28 0  4  -5 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1255 cmax				29 0  4  -6 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1255 tableoid			26 0  4  -7 0 -1 -1 t p i t f f t 0 f f));
 
 /* ----------------
  *		pg_attribute
  * ----------------
  */
 #define Schema_pg_attribute \
-{ 1249, {"attrelid"},	  26, -1,	4,	1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1249, {"attname"},	  19, -1, NAMEDATALEN,	2, 0, -1, -1, false, 'p', 'i', true, false, false, true, 0 }, \
-{ 1249, {"atttypid"},	  26, -1,	4,	3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1249, {"attstattarget"}, 23, -1,	4,	4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1249, {"attlen"},		  21, -1,	2,	5, 0, -1, -1, true, 'p', 's', true, false, false, true, 0 }, \
-{ 1249, {"attnum"},		  21, -1,	2,	6, 0, -1, -1, true, 'p', 's', true, false, false, true, 0 }, \
-{ 1249, {"attndims"},	  23, -1,	4,	7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1249, {"attcacheoff"},  23, -1,	4,	8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1249, {"atttypmod"},	  23, -1,	4,	9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1249, {"attbyval"},	  16, -1,	1, 10, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1249, {"attstorage"},   18, -1,	1, 11, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1249, {"attalign"},	  18, -1,	1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1249, {"attnotnull"},   16, -1,	1, 13, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1249, {"atthasdef"},	  16, -1,	1, 14, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1249, {"attisdropped"}, 16, -1,	1, 15, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1249, {"attislocal"},   16, -1,	1, 16, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1249, {"attinhcount"},  23, -1,	4, 17, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }
+{ 1249, {"attrelid"},	  26, -1,	4,	1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1249, {"attname"},	  19, -1, NAMEDATALEN,	2, 0, -1, -1, false, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1249, {"atttypid"},	  26, -1,	4,	3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1249, {"attstattarget"}, 23, -1,	4,	4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1249, {"attlen"},		  21, -1,	2,	5, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, false, false }, \
+{ 1249, {"attnum"},		  21, -1,	2,	6, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, false, false }, \
+{ 1249, {"attndims"},	  23, -1,	4,	7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1249, {"attcacheoff"},  23, -1,	4,	8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1249, {"atttypmod"},	  23, -1,	4,	9, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1249, {"attbyval"},	  16, -1,	1, 10, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1249, {"attstorage"},   18, -1,	1, 11, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1249, {"attalign"},	  18, -1,	1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1249, {"attnotnull"},   16, -1,	1, 13, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1249, {"atthasdef"},	  16, -1,	1, 14, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1249, {"attisdropped"}, 16, -1,	1, 15, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1249, {"attislocal"},   16, -1,	1, 16, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1249, {"attinhcount"},  23, -1,	4, 17, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1249, {"attidentity"},  16, -1,	1, 18, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1249, {"attforceddef"}, 16, -1,	1, 19, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }
 
-DATA(insert ( 1249 attrelid			26 -1  4   1 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1249 attname			19 -1 NAMEDATALEN  2 0 -1 -1 f p i t f f t 0));
-DATA(insert ( 1249 atttypid			26 -1  4   3 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1249 attstattarget	23 -1  4   4 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1249 attlen			21 -1  2   5 0 -1 -1 t p s t f f t 0));
-DATA(insert ( 1249 attnum			21 -1  2   6 0 -1 -1 t p s t f f t 0));
-DATA(insert ( 1249 attndims			23 -1  4   7 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1249 attcacheoff		23 -1  4   8 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1249 atttypmod		23 -1  4   9 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1249 attbyval			16 -1  1  10 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1249 attstorage		18 -1  1  11 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1249 attalign			18 -1  1  12 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1249 attnotnull		16 -1  1  13 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1249 atthasdef		16 -1  1  14 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1249 attisdropped		16 -1  1  15 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1249 attislocal		16 -1  1  16 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1249 attinhcount		23 -1  4  17 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1249 ctid				27 0  6  -1 0 -1 -1 f p s t f f t 0));
+
+DATA(insert ( 1249 attrelid			26 -1  4   1 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1249 attname			19 -1 NAMEDATALEN  2 0 -1 -1 f p i t f f t 0 f f));
+DATA(insert ( 1249 atttypid			26 -1  4   3 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1249 attstattarget	23 -1  4   4 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1249 attlen			21 -1  2   5 0 -1 -1 t p s t f f t 0 f f));
+DATA(insert ( 1249 attnum			21 -1  2   6 0 -1 -1 t p s t f f t 0 f f));
+DATA(insert ( 1249 attndims			23 -1  4   7 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1249 attcacheoff		23 -1  4   8 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1249 atttypmod		23 -1  4   9 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1249 attbyval			16 -1  1  10 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1249 attstorage		18 -1  1  11 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1249 attalign			18 -1  1  12 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1249 attnotnull		16 -1  1  13 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1249 atthasdef		16 -1  1  14 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1249 attisdropped		16 -1  1  15 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1249 attislocal		16 -1  1  16 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1249 attinhcount		23 -1  4  17 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1249 attidentity		16 -1  1  18 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1249 attforceddef		16 -1  1  19 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1249 ctid				27 0  6  -1 0 -1 -1 f p s t f f t 0 f f));
 /* no OIDs in pg_attribute */
-DATA(insert ( 1249 xmin				28 0  4  -3 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1249 cmin				29 0  4  -4 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1249 xmax				28 0  4  -5 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1249 cmax				29 0  4  -6 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1249 tableoid			26 0  4  -7 0 -1 -1 t p i t f f t 0));
+DATA(insert ( 1249 xmin				28 0  4  -3 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1249 cmin				29 0  4  -4 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1249 xmax				28 0  4  -5 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1249 cmax				29 0  4  -6 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1249 tableoid			26 0  4  -7 0 -1 -1 t p i t f f t 0 f f));
 
 /* ----------------
  *		pg_class
  * ----------------
  */
 #define Schema_pg_class \
-{ 1259, {"relname"},	   19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'i', true, false, false, true, 0 }, \
-{ 1259, {"relnamespace"},  26, -1,	4,	2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1259, {"reltype"},	   26, -1,	4,	3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1259, {"relowner"},	   26, -1,	4,	4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1259, {"relam"},		   26, -1,	4,	5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1259, {"relfilenode"},   26, -1,	4,	6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1259, {"reltablespace"}, 26, -1,	4,	7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1259, {"relpages"},	   23, -1,	4,	8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1259, {"reltuples"},	   700, -1, 4,	9, 0, -1, -1, false, 'p', 'i', true, false, false, true, 0 }, \
-{ 1259, {"reltoastrelid"}, 26, -1,	4, 10, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1259, {"reltoastidxid"}, 26, -1,	4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1259, {"relhasindex"},   16, -1,	1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1259, {"relisshared"},   16, -1,	1, 13, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1259, {"relkind"},	   18, -1,	1, 14, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1259, {"relnatts"},	   21, -1,	2, 15, 0, -1, -1, true, 'p', 's', true, false, false, true, 0 }, \
-{ 1259, {"relchecks"},	   21, -1,	2, 16, 0, -1, -1, true, 'p', 's', true, false, false, true, 0 }, \
-{ 1259, {"reltriggers"},   21, -1,	2, 17, 0, -1, -1, true, 'p', 's', true, false, false, true, 0 }, \
-{ 1259, {"relukeys"},	   21, -1,	2, 18, 0, -1, -1, true, 'p', 's', true, false, false, true, 0 }, \
-{ 1259, {"relfkeys"},	   21, -1,	2, 19, 0, -1, -1, true, 'p', 's', true, false, false, true, 0 }, \
-{ 1259, {"relrefs"},	   21, -1,	2, 20, 0, -1, -1, true, 'p', 's', true, false, false, true, 0 }, \
-{ 1259, {"relhasoids"},    16, -1,	1, 21, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1259, {"relhaspkey"},    16, -1,	1, 22, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1259, {"relhasrules"},   16, -1,	1, 23, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1259, {"relhassubclass"},16, -1,	1, 24, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 1259, {"relminxid"},     28, -1,	4, 25, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1259, {"relvacuumxid"},  28, -1,	4, 26, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 1259, {"relacl"},		 1034, -1, -1, 27, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0 }, \
-{ 1259, {"reloptions"},  1009, -1, -1, 28, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0 }
+{ 1259, {"relname"},	   19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1259, {"relnamespace"},  26, -1,	4,	2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1259, {"reltype"},	   26, -1,	4,	3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1259, {"relowner"},	   26, -1,	4,	4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1259, {"relam"},		   26, -1,	4,	5, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1259, {"relfilenode"},   26, -1,	4,	6, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1259, {"reltablespace"}, 26, -1,	4,	7, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1259, {"relpages"},	   23, -1,	4,	8, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1259, {"reltuples"},	   700, -1, 4,	9, 0, -1, -1, false, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1259, {"reltoastrelid"}, 26, -1,	4, 10, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1259, {"reltoastidxid"}, 26, -1,	4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1259, {"relhasindex"},   16, -1,	1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1259, {"relisshared"},   16, -1,	1, 13, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1259, {"relkind"},	   18, -1,	1, 14, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1259, {"relnatts"},	   21, -1,	2, 15, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, false, false }, \
+{ 1259, {"relchecks"},	   21, -1,	2, 16, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, false, false }, \
+{ 1259, {"reltriggers"},   21, -1,	2, 17, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, false, false }, \
+{ 1259, {"relukeys"},	   21, -1,	2, 18, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, false, false }, \
+{ 1259, {"relfkeys"},	   21, -1,	2, 19, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, false, false }, \
+{ 1259, {"relrefs"},	   21, -1,	2, 20, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, false, false }, \
+{ 1259, {"relhasoids"},    16, -1,	1, 21, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1259, {"relhaspkey"},    16, -1,	1, 22, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1259, {"relhasrules"},   16, -1,	1, 23, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1259, {"relhassubclass"},16, -1,	1, 24, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 1259, {"relminxid"},     28, -1,	4, 25, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1259, {"relvacuumxid"},  28, -1,	4, 26, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 1259, {"relacl"},		 1034, -1, -1, 27, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, false, false }, \
+{ 1259, {"reloptions"},  1009, -1, -1, 28, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, false, false }
 
-DATA(insert ( 1259 relname			19 -1 NAMEDATALEN	1 0 -1 -1 f p i t f f t 0));
-DATA(insert ( 1259 relnamespace		26 -1 4   2 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1259 reltype			26 -1 4   3 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1259 relowner			26 -1 4   4 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1259 relam			26 -1 4   5 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1259 relfilenode		26 -1 4   6 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1259 reltablespace	26 -1 4   7 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1259 relpages			23 -1 4   8 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1259 reltuples	   700 -1 4   9 0 -1 -1 f p i t f f t 0));
-DATA(insert ( 1259 reltoastrelid	26 -1 4  10 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1259 reltoastidxid	26 -1 4  11 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1259 relhasindex		16 -1 1  12 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1259 relisshared		16 -1 1  13 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1259 relkind			18 -1 1  14 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1259 relnatts			21 -1 2  15 0 -1 -1 t p s t f f t 0));
-DATA(insert ( 1259 relchecks		21 -1 2  16 0 -1 -1 t p s t f f t 0));
-DATA(insert ( 1259 reltriggers		21 -1 2  17 0 -1 -1 t p s t f f t 0));
-DATA(insert ( 1259 relukeys			21 -1 2  18 0 -1 -1 t p s t f f t 0));
-DATA(insert ( 1259 relfkeys			21 -1 2  19 0 -1 -1 t p s t f f t 0));
-DATA(insert ( 1259 relrefs			21 -1 2  20 0 -1 -1 t p s t f f t 0));
-DATA(insert ( 1259 relhasoids		16 -1 1  21 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1259 relhaspkey		16 -1 1  22 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1259 relhasrules		16 -1 1  23 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1259 relhassubclass	16 -1 1  24 0 -1 -1 t p c t f f t 0));
-DATA(insert ( 1259 relminxid		28 -1 4  25 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1259 relvacuumxid		28 -1 4  26 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1259 relacl		  1034 -1 -1 27 1 -1 -1 f x i f f f t 0));
-DATA(insert ( 1259 reloptions	  1009 -1 -1 28 1 -1 -1 f x i f f f t 0));
-DATA(insert ( 1259 ctid				27 0  6  -1 0 -1 -1 f p s t f f t 0));
-DATA(insert ( 1259 oid				26 0  4  -2 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1259 xmin				28 0  4  -3 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1259 cmin				29 0  4  -4 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1259 xmax				28 0  4  -5 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1259 cmax				29 0  4  -6 0 -1 -1 t p i t f f t 0));
-DATA(insert ( 1259 tableoid			26 0  4  -7 0 -1 -1 t p i t f f t 0));
+DATA(insert ( 1259 relname			19 -1 NAMEDATALEN	1 0 -1 -1 f p i t f f t 0 f f));
+DATA(insert ( 1259 relnamespace		26 -1 4   2 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1259 reltype			26 -1 4   3 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1259 relowner			26 -1 4   4 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1259 relam			26 -1 4   5 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1259 relfilenode		26 -1 4   6 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1259 reltablespace	26 -1 4   7 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1259 relpages			23 -1 4   8 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1259 reltuples	   700 -1 4   9 0 -1 -1 f p i t f f t 0 f f));
+DATA(insert ( 1259 reltoastrelid	26 -1 4  10 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1259 reltoastidxid	26 -1 4  11 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1259 relhasindex		16 -1 1  12 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1259 relisshared		16 -1 1  13 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1259 relkind			18 -1 1  14 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1259 relnatts			21 -1 2  15 0 -1 -1 t p s t f f t 0 f f));
+DATA(insert ( 1259 relchecks		21 -1 2  16 0 -1 -1 t p s t f f t 0 f f));
+DATA(insert ( 1259 reltriggers		21 -1 2  17 0 -1 -1 t p s t f f t 0 f f));
+DATA(insert ( 1259 relukeys			21 -1 2  18 0 -1 -1 t p s t f f t 0 f f));
+DATA(insert ( 1259 relfkeys			21 -1 2  19 0 -1 -1 t p s t f f t 0 f f));
+DATA(insert ( 1259 relrefs			21 -1 2  20 0 -1 -1 t p s t f f t 0 f f));
+DATA(insert ( 1259 relhasoids		16 -1 1  21 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1259 relhaspkey		16 -1 1  22 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1259 relhasrules		16 -1 1  23 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1259 relhassubclass	16 -1 1  24 0 -1 -1 t p c t f f t 0 f f));
+DATA(insert ( 1259 relminxid		28 -1 4  25 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1259 relvacuumxid		28 -1 4  26 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1259 relacl		  1034 -1 -1 27 1 -1 -1 f x i f f f t 0 f f));
+DATA(insert ( 1259 reloptions	  1009 -1 -1 28 1 -1 -1 f x i f f f t 0 f f));
+DATA(insert ( 1259 ctid				27 0  6  -1 0 -1 -1 f p s t f f t 0 f f));
+DATA(insert ( 1259 oid				26 0  4  -2 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1259 xmin				28 0  4  -3 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1259 cmin				29 0  4  -4 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1259 xmax				28 0  4  -5 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1259 cmax				29 0  4  -6 0 -1 -1 t p i t f f t 0 f f));
+DATA(insert ( 1259 tableoid			26 0  4  -7 0 -1 -1 t p i t f f t 0 f f));
 
 /* ----------------
  *		pg_index
@@ -454,15 +467,15 @@ DATA(insert ( 1259 tableoid			26 0  4  -
  * ----------------
  */
 #define Schema_pg_index \
-{ 0, {"indexrelid"},		26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 0, {"indrelid"},			26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
-{ 0, {"indnatts"},			21, -1, 2, 3, 0, -1, -1, true, 'p', 's', true, false, false, true, 0 }, \
-{ 0, {"indisunique"},		16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 0, {"indisprimary"},		16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 0, {"indisclustered"},	16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0 }, \
-{ 0, {"indkey"},			22, -1, -1, 7, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0 }, \
-{ 0, {"indclass"},			30, -1, -1, 8, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0 }, \
-{ 0, {"indexprs"},			25, -1, -1, 9, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0 }, \
-{ 0, {"indpred"},			25, -1, -1, 10, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0 }
+{ 0, {"indexrelid"},		26, -1, 4, 1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 0, {"indrelid"},			26, -1, 4, 2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 0, {"indnatts"},			21, -1, 2, 3, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, false, false }, \
+{ 0, {"indisunique"},		16, -1, 1, 4, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 0, {"indisprimary"},		16, -1, 1, 5, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 0, {"indisclustered"},	16, -1, 1, 6, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, false, false }, \
+{ 0, {"indkey"},			22, -1, -1, 7, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 0, {"indclass"},			30, -1, -1, 8, 1, -1, -1, false, 'p', 'i', true, false, false, true, 0, false, false }, \
+{ 0, {"indexprs"},			25, -1, -1, 9, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, false, false }, \
+{ 0, {"indpred"},			25, -1, -1, 10, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0, false, false }
 
 #endif   /* PG_ATTRIBUTE_H */
diff -durpN pgsql.orig/src/include/catalog/pg_class.h pgsql/src/include/catalog/pg_class.h
--- pgsql.orig/src/include/catalog/pg_class.h	2006-07-11 16:09:46.000000000 +0200
+++ pgsql/src/include/catalog/pg_class.h	2006-08-09 17:20:20.000000000 +0200
@@ -135,7 +135,7 @@ typedef FormData_pg_class *Form_pg_class
 /* Note: the "3" here stands for FirstNormalTransactionId */
 DATA(insert OID = 1247 (  pg_type		PGNSP 71 PGUID 0 1247 0 0 0 0 0 f f r 23 0 0 0 0 0 t f f f 3 3 _null_ _null_ ));
 DESCR("");
-DATA(insert OID = 1249 (  pg_attribute	PGNSP 75 PGUID 0 1249 0 0 0 0 0 f f r 17 0 0 0 0 0 f f f f 3 3 _null_ _null_ ));
+DATA(insert OID = 1249 (  pg_attribute	PGNSP 75 PGUID 0 1249 0 0 0 0 0 f f r 19 0 0 0 0 0 f f f f 3 3 _null_ _null_ ));
 DESCR("");
 DATA(insert OID = 1255 (  pg_proc		PGNSP 81 PGUID 0 1255 0 0 0 0 0 f f r 18 0 0 0 0 0 t f f f 3 3 _null_ _null_ ));
 DESCR("");
diff -durpN pgsql.orig/src/include/nodes/parsenodes.h pgsql/src/include/nodes/parsenodes.h
--- pgsql.orig/src/include/nodes/parsenodes.h	2006-08-03 10:37:52.000000000 +0200
+++ pgsql/src/include/nodes/parsenodes.h	2006-08-09 17:20:20.000000000 +0200
@@ -129,6 +129,8 @@ typedef struct Query
 	 * some sort of TopPlan plan node, not in the Query.
 	 */
 	List	   *resultRelations;	/* integer list of RT indexes, or NIL */
+
+	bool		commandOverride;	/* OVERRIDING SYSTEM | USER VALUE */
 } Query;
 
 
@@ -394,6 +396,8 @@ typedef struct ColumnDef
 	char	   *cooked_default; /* nodeToString representation */
 	List	   *constraints;	/* other constraints on column */
 	RangeVar   *support;		/* supporting relation, if any */
+	bool		is_identity;	/* GENERATED AS IDENTITY */
+	bool		force_default;	/* GENERATED ALWAYS */
 } ColumnDef;
 
 /*
@@ -648,6 +652,7 @@ typedef struct InsertStmt
 	RangeVar   *relation;		/* relation to insert into */
 	List	   *cols;			/* optional: names of the target columns */
 	Node	   *selectStmt;		/* the source SELECT/VALUES, or NULL */
+	bool		override_def;	/* OVERRIDING { USER | SYSTEM } VALUE */
 } InsertStmt;
 
 /* ----------------------
@@ -881,7 +886,8 @@ typedef enum AlterTableType
 	AT_EnableTrigUser,			/* ENABLE TRIGGER USER */
 	AT_DisableTrigUser,			/* DISABLE TRIGGER USER */
 	AT_AddInherits,				/* ADD INHERITS parent */
-	AT_DropInherits				/* DROP INHERITS parent */
+	AT_DropInherits,				/* DROP INHERITS parent */
+	AT_SetSeqOpts				/* SET sequence_options for IDENTITY columns */
 } AlterTableType;
 
 typedef struct AlterTableCmd	/* one subcommand of an ALTER TABLE */
@@ -1008,6 +1014,7 @@ typedef struct CopyStmt
 	bool		is_from;		/* TO or FROM */
 	char	   *filename;		/* if NULL, use stdin/stdout */
 	List	   *options;		/* List of DefElem nodes */
+	bool		overriding;	/* OVERRIDING SYSTEM VALUE */
 } CopyStmt;
 
 /* ----------------------
@@ -1076,7 +1083,8 @@ typedef enum ConstrType			/* types of co
 	CONSTR_ATTR_DEFERRABLE,		/* attributes for previous constraint node */
 	CONSTR_ATTR_NOT_DEFERRABLE,
 	CONSTR_ATTR_DEFERRED,
-	CONSTR_ATTR_IMMEDIATE
+	CONSTR_ATTR_IMMEDIATE,
+	CONSTR_IDENTITY
 } ConstrType;
 
 typedef struct Constraint
@@ -1090,6 +1098,8 @@ typedef struct Constraint
 	List	   *options;		/* options from WITH clause */
 	char	   *indexspace;		/* index tablespace for PKEY/UNIQUE
 								 * constraints; NULL for default */
+	bool		force_default;	/* GENERATED ALWAYS */
+	List	   *seq_opts;		/* SEQUENCE options for GENERATED ... AS IDENTITY */
 } Constraint;
 
 /* ----------
diff -durpN pgsql.orig/src/include/utils/acl.h pgsql/src/include/utils/acl.h
--- pgsql.orig/src/include/utils/acl.h	2006-05-04 00:45:26.000000000 +0200
+++ pgsql/src/include/utils/acl.h	2006-08-09 17:20:20.000000000 +0200
@@ -245,6 +245,7 @@ extern Datum hash_aclitem(PG_FUNCTION_AR
  */
 extern void ExecuteGrantStmt(GrantStmt *stmt);
 extern void ExecGrantStmt_oids(InternalGrant *istmt);
+extern void ExecGrant_Sequence(Oid relOid, int attnum, Oid seqOid);
 
 extern AclMode pg_class_aclmask(Oid table_oid, Oid roleid,
 				 AclMode mask, AclMaskHow how);
diff -durpN pgsql.orig/src/include/utils/lsyscache.h pgsql/src/include/utils/lsyscache.h
--- pgsql.orig/src/include/utils/lsyscache.h	2006-07-14 13:52:06.000000000 +0200
+++ pgsql/src/include/utils/lsyscache.h	2006-08-09 17:20:20.000000000 +0200
@@ -38,6 +38,7 @@ extern void get_op_btree_interpretation(
 extern Oid	get_opclass_proc(Oid opclass, Oid subtype, int16 procnum);
 extern char *get_attname(Oid relid, AttrNumber attnum);
 extern char *get_relid_attribute_name(Oid relid, AttrNumber attnum);
+extern Oid	get_relid_att_serial_sequence(Oid relid, AttrNumber attnum);
 extern AttrNumber get_attnum(Oid relid, const char *attname);
 extern Oid	get_atttype(Oid relid, AttrNumber attnum);
 extern int32 get_atttypmod(Oid relid, AttrNumber attnum);
diff -durpN pgsql.orig/src/test/regress/expected/alter_table.out pgsql/src/test/regress/expected/alter_table.out
--- pgsql.orig/src/test/regress/expected/alter_table.out	2006-07-03 23:34:31.000000000 +0200
+++ pgsql/src/test/regress/expected/alter_table.out	2006-08-09 17:20:20.000000000 +0200
@@ -1312,19 +1312,20 @@ alter table anothertab alter column atco
         using case when atcol1 % 2 = 0 then true else false end; -- fails
 ERROR:  default for column "atcol1" cannot be cast to type "pg_catalog.bool"
 alter table anothertab alter column atcol1 drop default;
+ERROR:  cannot alter IDENTITY column "atcol1"
 alter table anothertab alter column atcol1 type boolean
         using case when atcol1 % 2 = 0 then true else false end; -- fails
-ERROR:  operator does not exist: boolean <= integer
-HINT:  No operator matches the given name and argument type(s). You may need to add explicit type casts.
+ERROR:  default for column "atcol1" cannot be cast to type "pg_catalog.bool"
 alter table anothertab drop constraint anothertab_chk;
 alter table anothertab alter column atcol1 type boolean
         using case when atcol1 % 2 = 0 then true else false end;
+ERROR:  default for column "atcol1" cannot be cast to type "pg_catalog.bool"
 select * from anothertab;
  atcol1 |    atcol2    
 --------+--------------
- f      | IT WAS TRUE
- t      | IT WAS FALSE
- f      | IT WAS NULL!
+      1 | IT WAS TRUE
+      2 | IT WAS FALSE
+      3 | IT WAS NULL!
 (3 rows)
 
 drop table anothertab;
diff -durpN pgsql.orig/src/test/regress/expected/identity.out pgsql/src/test/regress/expected/identity.out
--- pgsql.orig/src/test/regress/expected/identity.out	1970-01-01 01:00:00.000000000 +0100
+++ pgsql/src/test/regress/expected/identity.out	2006-08-09 17:20:20.000000000 +0200
@@ -0,0 +1,342 @@
+--
+-- IDENTITY
+--  2006.08.01 Zoltan Boszormenyi <zboszor@dunaweb.hu>
+--
+--
+-- Test GENERATED BY DEFAULT AS IDENTITY with default sequence
+--
+create table id (id serial generated by default as identity primary key, name text);
+NOTICE:  CREATE TABLE will create implicit sequence "id_id_seq" for serial column "id.id"
+NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "id_pkey" for table "id"
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (0, 'a');
+--
+-- This must complain about UNIQUE violation
+--
+insert into id (id, name) values (0, 'a');
+ERROR:  duplicate key violates unique constraint "id_pkey"
+select * from id;
+ id | name 
+----+------
+  1 | a
+  2 | a
+  3 | a
+  0 | a
+(4 rows)
+
+drop table id;
+--
+-- Test GENERATED BY DEFAULT AS IDENTITY with modified sequence
+--
+create table id (id serial generated by default as identity(start 3) primary key, name text);
+NOTICE:  CREATE TABLE will create implicit sequence "id_id_seq" for serial column "id.id"
+NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "id_pkey" for table "id"
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (0, 'a');
+--
+-- This must complain about UNIQUE violation
+--
+insert into id (id, name) values (0, 'a');
+ERROR:  duplicate key violates unique constraint "id_pkey"
+select * from id;
+ id | name 
+----+------
+  3 | a
+  4 | a
+  5 | a
+  0 | a
+(4 rows)
+
+drop table id;
+--
+-- Test GENERATED ALWAYS AS IDENTITY with default sequence
+--
+create table id (id serial generated always as identity primary key, name text);
+NOTICE:  CREATE TABLE will create implicit sequence "id_id_seq" for serial column "id.id"
+NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "id_pkey" for table "id"
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (0, 'a');
+insert into id (id, name) values (0, 'a');
+insert into id (id, name) values (0, 'a');
+select * from id;
+ id | name 
+----+------
+  1 | a
+  2 | a
+  3 | a
+  4 | a
+  5 | a
+  6 | a
+(6 rows)
+
+--
+-- It should update 0 rows
+--
+update id set name = 'b' where id = 0;
+select * from id;
+ id | name 
+----+------
+  1 | a
+  2 | a
+  3 | a
+  4 | a
+  5 | a
+  6 | a
+(6 rows)
+
+drop table id;
+--
+-- Test GENERATED ALWAYS AS IDENTITY with modified sequence
+--
+create table id (id serial generated always as identity(start 3) primary key, name text);
+NOTICE:  CREATE TABLE will create implicit sequence "id_id_seq" for serial column "id.id"
+NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "id_pkey" for table "id"
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (0, 'a');
+insert into id (id, name) values (0, 'a');
+insert into id (id, name) values (0, 'a');
+select * from id;
+ id | name 
+----+------
+  3 | a
+  4 | a
+  5 | a
+  6 | a
+  7 | a
+  8 | a
+(6 rows)
+
+--
+-- It should update 0 rows
+--
+update id set name = 'b' where id = 0;
+select * from id;
+ id | name 
+----+------
+  3 | a
+  4 | a
+  5 | a
+  6 | a
+  7 | a
+  8 | a
+(6 rows)
+
+drop table id;
+--
+-- Test GENERATED BY DEFAULT AS (expr)
+-- It must give a syntax error but drop it anyway.
+--
+create table id (id integer generated by default as (1), name text);
+ERROR:  syntax error at or near "("
+LINE 1: ...eate table id (id integer generated by default as (1), name ...
+                                                             ^
+drop table id;
+ERROR:  table "id" does not exist
+--
+-- Test GENERATED ALWAYS AS ( expr )
+--
+create table id (id integer generated always as (1), name text);
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (0, 'a');
+select * from id;
+ id | name 
+----+------
+  1 | a
+  1 | a
+(2 rows)
+
+--
+-- It should update 0 rows
+--
+update id set name = 'b' where id = 0;
+select * from id;
+ id | name 
+----+------
+  1 | a
+  1 | a
+(2 rows)
+
+drop table id;
+--
+-- Test IDENTITY with non-integer columns
+--
+create table id (id decimal(10,2) generated always as identity(start 3), name text);
+NOTICE:  CREATE TABLE will create implicit sequence "id_id_seq" for serial column "id.id"
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (0, 'a');
+select * from id;
+  id  | name 
+------+------
+ 3.00 | a
+ 4.00 | a
+(2 rows)
+
+alter table id alter id type real;
+insert into id (id, name) values (0, 'a');
+select * from id;
+ id | name 
+----+------
+  3 | a
+  4 | a
+  5 | a
+(3 rows)
+
+alter table id alter id type integer;
+insert into id (id, name) values (0, 'a');
+select * from id;
+ id | name 
+----+------
+  3 | a
+  4 | a
+  5 | a
+  6 | a
+(4 rows)
+
+--
+-- It should update 0 rows
+--
+update id set name = 'b' where id = 0;
+select * from id;
+ id | name 
+----+------
+  3 | a
+  4 | a
+  5 | a
+  6 | a
+(4 rows)
+
+update id set name = 'b' where id = 5;
+select * from id;
+ id | name 
+----+------
+  3 | a
+  4 | a
+  6 | a
+  5 | b
+(4 rows)
+
+drop table id;
+--
+-- Test OVERRIDING and UPDATE on GENERATED ALWAYS columns
+--
+create table id (id serial generated always as identity, name text generated always as ('x'));
+NOTICE:  CREATE TABLE will create implicit sequence "id_id_seq" for serial column "id.id"
+insert into id (id, name) values (0, 'a');
+insert into id (id, name) overriding user value values (0, 'a');
+insert into id (id, name) overriding system value values (0, 'a');
+--
+-- It's expected to fail because of GENERATED ALWAYS AS IDENTITY.
+--
+update id set id = 6 where id = 0;
+ERROR:  UPDATE prohibited on GENERATED ALWAYS AS IDENTITY attributes
+--
+-- It's expected to fail because of GENERATED ALWAYS AS IDENTITY.
+--
+update id set id = default where id = 0;
+ERROR:  UPDATE prohibited on GENERATED ALWAYS AS IDENTITY attributes
+--
+-- It's expected to fail because of GENERATED ALWAYS.
+--
+update id set name = 'b' where id = 0;
+ERROR:  UPDATE to non-default value prohibited on GENERATED ALWAYS attributes
+--
+-- It's expected to succeed
+--
+update id set name = default where id = 0;
+--
+-- Test ALTER TABLE sequence options
+--
+alter table id alter id restart with 10;
+insert into id (id, name) values (0, 'a');
+alter table id alter id set increment by 5;
+insert into id (id, name) values (0, 'a');
+select * from id;
+ id | name 
+----+------
+  1 | x
+  2 | x
+  0 | x
+ 10 | x
+ 15 | x
+(5 rows)
+
+--
+-- Test ALTER TABLE RENAME
+--
+select pg_get_serial_sequence('id', 'id');
+ pg_get_serial_sequence 
+------------------------
+ public.id_id_seq
+(1 row)
+
+alter table id rename id to di;
+NOTICE:  supporting sequence for column "di" renamed to "id_di_seq"
+insert into id (di, name) values (0, 'a');
+select pg_get_serial_sequence('id', 'di');
+ pg_get_serial_sequence 
+------------------------
+ public.id_di_seq
+(1 row)
+
+alter table id rename to di;
+NOTICE:  supporting sequence for column "di" renamed to "di_di_seq"
+insert into di (di, name) values (0, 'a');
+select pg_get_serial_sequence('di', 'di');
+ pg_get_serial_sequence 
+------------------------
+ public.di_di_seq
+(1 row)
+
+select * from di;
+ di | name 
+----+------
+  1 | x
+  2 | x
+  0 | x
+ 10 | x
+ 15 | x
+ 20 | x
+ 25 | x
+(7 rows)
+
+--
+-- Test SET/DROP DEFAULT
+--
+alter table di alter di drop default;
+ERROR:  cannot alter IDENTITY column "di"
+alter table di alter di set default 1;
+ERROR:  cannot alter IDENTITY column "di"
+--
+-- Test ALTER TABLE DROP COLUMN
+--
+alter table di add column id integer;
+update di set id = di;
+alter table di drop column di;
+select * from di;
+ name | id 
+------+----
+ x    |  1
+ x    |  2
+ x    |  0
+ x    | 10
+ x    | 15
+ x    | 20
+ x    | 25
+(7 rows)
+
+drop table di;
+--
+-- Test fancy col1+col2 GENERATED columns
+--
+--create table id (id serial, i1 integer, i2 integer, g integer generated always as (i1+i2));
+--insert into id (i1, i2) values (1,2);
+--select * from id;
+--drop table id;
diff -durpN pgsql.orig/src/test/regress/identity_schedule pgsql/src/test/regress/identity_schedule
--- pgsql.orig/src/test/regress/identity_schedule	1970-01-01 01:00:00.000000000 +0100
+++ pgsql/src/test/regress/identity_schedule	2006-08-09 17:20:20.000000000 +0200
@@ -0,0 +1,6 @@
+# ----------
+# The first group of parallel test
+# $PostgreSQL: pgsql/src/test/regress/parallel_schedule,v 1.32 2006/03/11 04:38:41 momjian Exp $
+# ----------
+test: identity
+
diff -durpN pgsql.orig/src/test/regress/parallel_schedule pgsql/src/test/regress/parallel_schedule
--- pgsql.orig/src/test/regress/parallel_schedule	2006-08-05 16:46:55.000000000 +0200
+++ pgsql/src/test/regress/parallel_schedule	2006-08-09 17:20:20.000000000 +0200
@@ -2,7 +2,7 @@
 # The first group of parallel test
 # $PostgreSQL: pgsql/src/test/regress/parallel_schedule,v 1.33 2006/08/04 00:00:13 tgl Exp $
 # ----------
-test: boolean char name varchar text int2 int4 int8 oid float4 float8 bit numeric
+test: boolean char name varchar text int2 int4 int8 oid float4 float8 bit numeric identity
 
 # Depends on things setup during char, varchar and text
 test: strings
diff -durpN pgsql.orig/src/test/regress/sql/identity.sql pgsql/src/test/regress/sql/identity.sql
--- pgsql.orig/src/test/regress/sql/identity.sql	1970-01-01 01:00:00.000000000 +0100
+++ pgsql/src/test/regress/sql/identity.sql	2006-08-09 17:20:20.000000000 +0200
@@ -0,0 +1,186 @@
+--
+-- IDENTITY
+--  2006.08.01 Zoltan Boszormenyi <zboszor@dunaweb.hu>
+--
+
+--
+-- Test GENERATED BY DEFAULT AS IDENTITY with default sequence
+--
+
+create table id (id serial generated by default as identity primary key, name text);
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (0, 'a');
+--
+-- This must complain about UNIQUE violation
+--
+insert into id (id, name) values (0, 'a');
+select * from id;
+drop table id;
+
+--
+-- Test GENERATED BY DEFAULT AS IDENTITY with modified sequence
+--
+
+create table id (id serial generated by default as identity(start 3) primary key, name text);
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (0, 'a');
+--
+-- This must complain about UNIQUE violation
+--
+insert into id (id, name) values (0, 'a');
+select * from id;
+drop table id;
+
+--
+-- Test GENERATED ALWAYS AS IDENTITY with default sequence
+--
+
+create table id (id serial generated always as identity primary key, name text);
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (0, 'a');
+insert into id (id, name) values (0, 'a');
+insert into id (id, name) values (0, 'a');
+select * from id;
+--
+-- It should update 0 rows
+--
+update id set name = 'b' where id = 0;
+select * from id;
+drop table id;
+
+--
+-- Test GENERATED ALWAYS AS IDENTITY with modified sequence
+--
+
+create table id (id serial generated always as identity(start 3) primary key, name text);
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (0, 'a');
+insert into id (id, name) values (0, 'a');
+insert into id (id, name) values (0, 'a');
+select * from id;
+--
+-- It should update 0 rows
+--
+update id set name = 'b' where id = 0;
+select * from id;
+drop table id;
+
+--
+-- Test GENERATED BY DEFAULT AS (expr)
+-- It must give a syntax error but drop it anyway.
+--
+
+create table id (id integer generated by default as (1), name text);
+drop table id;
+
+--
+-- Test GENERATED ALWAYS AS ( expr )
+--
+
+create table id (id integer generated always as (1), name text);
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (0, 'a');
+select * from id;
+--
+-- It should update 0 rows
+--
+update id set name = 'b' where id = 0;
+select * from id;
+drop table id;
+
+--
+-- Test IDENTITY with non-integer columns
+--
+
+create table id (id decimal(10,2) generated always as identity(start 3), name text);
+insert into id (id, name) values (default, 'a');
+insert into id (id, name) values (0, 'a');
+select * from id;
+alter table id alter id type real;
+insert into id (id, name) values (0, 'a');
+select * from id;
+alter table id alter id type integer;
+insert into id (id, name) values (0, 'a');
+select * from id;
+--
+-- It should update 0 rows
+--
+update id set name = 'b' where id = 0;
+select * from id;
+update id set name = 'b' where id = 5;
+select * from id;
+drop table id;
+
+--
+-- Test OVERRIDING and UPDATE on GENERATED ALWAYS columns
+--
+
+create table id (id serial generated always as identity, name text generated always as ('x'));
+insert into id (id, name) values (0, 'a');
+insert into id (id, name) overriding user value values (0, 'a');
+insert into id (id, name) overriding system value values (0, 'a');
+--
+-- It's expected to fail because of GENERATED ALWAYS AS IDENTITY.
+--
+update id set id = 6 where id = 0;
+--
+-- It's expected to fail because of GENERATED ALWAYS AS IDENTITY.
+--
+update id set id = default where id = 0;
+--
+-- It's expected to fail because of GENERATED ALWAYS.
+--
+update id set name = 'b' where id = 0;
+--
+-- It's expected to succeed
+--
+update id set name = default where id = 0;
+--
+-- Test ALTER TABLE sequence options
+--
+alter table id alter id restart with 10;
+insert into id (id, name) values (0, 'a');
+alter table id alter id set increment by 5;
+insert into id (id, name) values (0, 'a');
+select * from id;
+--
+-- Test ALTER TABLE RENAME
+--
+select pg_get_serial_sequence('id', 'id');
+alter table id rename id to di;
+insert into id (di, name) values (0, 'a');
+select pg_get_serial_sequence('id', 'di');
+alter table id rename to di;
+insert into di (di, name) values (0, 'a');
+select pg_get_serial_sequence('di', 'di');
+select * from di;
+--
+-- Test SET/DROP DEFAULT
+--
+alter table di alter di drop default;
+alter table di alter di set default 1;
+--
+-- Test ALTER TABLE DROP COLUMN
+--
+alter table di add column id integer;
+update di set id = di;
+alter table di drop column di;
+select * from di;
+
+drop table di;
+
+--
+-- Test fancy col1+col2 GENERATED columns
+--
+--create table id (id serial, i1 integer, i2 integer, g integer generated always as (i1+i2));
+--insert into id (i1, i2) values (1,2);
+--select * from id;
+--drop table id;
