From: Bruce Momjian Date: Mon, 3 Oct 2005 01:57:59 +0000 (+0000) Subject: Update release notes to show how to upgrade a database to use the new X-Git-Url: http://waps.l3s.uni-hannover.de/gitweb/?a=commitdiff_plain;h=36fa1f0b2a807426b6ed2365cdc0d34df1a0e78f;p=users%2Fbernd%2Fpostgres.git Update release notes to show how to upgrade a database to use the new early binding for nextval() calls in default clauses. --- diff --git a/doc/src/sgml/release.sgml b/doc/src/sgml/release.sgml index 39d358be1d..f1d6086af9 100644 --- a/doc/src/sgml/release.sgml +++ b/doc/src/sgml/release.sgml @@ -262,6 +262,21 @@ pg_[A-Za-z0-9_] + + + Add proper sequence function dependencies (Tom) + + + In previous releases, nextval(), + currval, and setval() recorded + sequence names as simple text strings, meaning that renaming or + dropping a sequence used in a DEFAULT made the + clause invalid. This release stores all newly-created sequence + function arguments using internal oids, allowing them to handle + sequence renaming, and adding dependency information that + + + add_missing_from is now false by default (Neil) @@ -398,16 +413,53 @@ pg_[A-Za-z0-9_] When an expression like nextval('myseq') appears in a - column default expression or view, the referenced sequence (here - myseq) is now looked up immediately, and its pg_class - OID is placed in the stored expression. This representation will - survive renaming of the referenced sequence, as well as changes in - schema search paths. The system also understands that the sequence - reference represents a dependency, so the sequence cannot be dropped - without dropping the referencing object. To get the old behavior of - run-time lookup of the sequence by name, cast the argument to - text, for example nextval('myseq'::text). + column DEFAULT expression or view, the referenced + sequence (here myseq) is now looked up immediately, + and its pg_class OID is placed in the stored expression. This + representation will survive renaming of the referenced sequence, + as well as changes in schema search paths. The system also + understands that the sequence reference represents a dependency, + so the sequence cannot be dropped without dropping the + referencing object. Previous releases stored this information as + a simple text string, with none of the benefits outlined above. + To get the old text-based behavior of run-time lookup of the + sequence name, cast the argument to text, for example + nextval('myseq'::text). + + Pre-8.1 schemas loaded into 8.1 will use the previous, text-based + representation and therefore will not have these protections. + However, it is possible to upgrade a database to the newer + OID-based arguments. First, save this query into a file, such as + fixseq.sql: + +SELECT 'ALTER TABLE ' || + pg_catalog.quote_ident(n.nspname) || '.' || + pg_catalog.quote_ident(c.relname) || + ' ALTER COLUMN ' || pg_catalog.quote_ident(a.attname) || + ' SET DEFAULT ' || + regexp_replace(d.adsrc, '(nextval\\(''[^'']*'')::text', '\\1', 'g') || + ';' +FROM pg_namespace n, pg_class c, pg_attribute a, pg_attrdef d +WHERE n.oid = c.relnamespace AND + c.oid = a.attrelid AND + a.attrelid = d.adrelid AND + a.attnum = d.adnum AND + d.adsrc ~ '.*nextval\\(''[^'']*''::text'; + + Next, run the query against a database to find what + adjustments are required, like this for database db1: + +psql -aT -f fixseq.sql db1 + + This will show the ALTER TABLE commands needed to + convert the database to the newer OID-based representation. + Finally, run this to update the database: + +psql -aT -f fixseq.sql db1 | psql -e db1 + + This process should be done for each database loaded with pre-8.1 + schemas.