|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/catalog/pg_constraint.c,v 1.29 2006/02/11 22:17:18 momjian Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/catalog/pg_constraint.c,v 1.30 2006/02/12 19:11:01 momjian Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -664,191 +664,3 @@ AlterConstraintNamespaces(Oid ownerId, Oid oldNspId,
|
664 | 664 |
|
665 | 665 | heap_close(conRel, RowExclusiveLock);
|
666 | 666 | }
|
667 |
| - |
668 |
| - |
669 |
| -/* |
670 |
| - * RenameConstraint |
671 |
| - * Rename a single constraint record |
672 |
| - * conId: The OID of the constraint to rename |
673 |
| - * newName: The new name of the constraint |
674 |
| - * implicitRename: is this an implicit rename? If so, we will issue |
675 |
| - * a notice about the implicit rename |
676 |
| - * cmdName: the command that triggered the rename for the "implicitly |
677 |
| - * renames" notice message |
678 |
| - */ |
679 |
| -void |
680 |
| -RenameConstraint(Oid conId, const char* newName, |
681 |
| - bool implicitRename, const char* cmdName) |
682 |
| -{ |
683 |
| - Relation conRel; |
684 |
| - ScanKeyData key[1]; |
685 |
| - SysScanDesc scan; |
686 |
| - HeapTuple tup; |
687 |
| - NameData newNameData; |
688 |
| - Relation rel; |
689 |
| - Oid relId; |
690 |
| - Oid nspOid; |
691 |
| - Form_pg_constraint conform; |
692 |
| - |
693 |
| - /* before reading the tuple, lock the table it constraints in |
694 |
| - * AccessExclusiveLock mode. Otherwise, if we read it before locking this |
695 |
| - * table, the tuple might be changed by another transaction and our copy |
696 |
| - * would be out of date |
697 |
| - */ |
698 |
| - relId = GetConstraintRelationId(conId); |
699 |
| - if (!OidIsValid(relId)) |
700 |
| - { |
701 |
| - ereport(ERROR, |
702 |
| - (errcode(ERRCODE_UNDEFINED_OBJECT), |
703 |
| - errmsg("constraint with OID %d does not exist", conId))); |
704 |
| - } |
705 |
| - |
706 |
| - rel = relation_open(relId, AccessExclusiveLock); |
707 |
| - nspOid = get_rel_namespace(relId); |
708 |
| - |
709 |
| - conRel = heap_open(ConstraintRelationId, RowExclusiveLock); |
710 |
| - |
711 |
| - ScanKeyInit(&key[0], |
712 |
| - ObjectIdAttributeNumber, |
713 |
| - BTEqualStrategyNumber, F_OIDEQ, |
714 |
| - ObjectIdGetDatum(conId)); |
715 |
| - |
716 |
| - scan = systable_beginscan(conRel, ConstraintOidIndexId, true, |
717 |
| - SnapshotNow, 1, key); |
718 |
| - if (!HeapTupleIsValid((tup = systable_getnext(scan)))) |
719 |
| - { |
720 |
| - ereport(ERROR, |
721 |
| - (errcode(ERRCODE_UNDEFINED_OBJECT), |
722 |
| - errmsg("constraint with OID %d does not exist", conId))); |
723 |
| - } |
724 |
| - |
725 |
| - conform = (Form_pg_constraint) GETSTRUCT(tup); |
726 |
| - |
727 |
| - if (ConstraintNameIsUsed(CONSTRAINT_RELATION, |
728 |
| - conform->conrelid, |
729 |
| - get_rel_namespace(conform->conrelid), |
730 |
| - newName)) |
731 |
| - { |
732 |
| - ereport(ERROR, |
733 |
| - (errcode(ERRCODE_DUPLICATE_OBJECT), |
734 |
| - errmsg("constraint \"%s\" for relation \"%s\" already exists", |
735 |
| - newName, |
736 |
| - RelationGetRelationName(rel)))); |
737 |
| - } |
738 |
| - tup = heap_copytuple(tup); |
739 |
| - conform = (Form_pg_constraint) GETSTRUCT(tup); |
740 |
| - |
741 |
| - if (implicitRename && cmdName) |
742 |
| - { |
743 |
| - ereport(NOTICE, |
744 |
| - (errmsg("%s will implicitly rename constraint " |
745 |
| - "\"%s\" to \"%s\" on table \"%s.%s\"", |
746 |
| - cmdName, |
747 |
| - NameStr(conform->conname), |
748 |
| - newName, |
749 |
| - get_namespace_name(nspOid), |
750 |
| - RelationGetRelationName(rel)))); |
751 |
| - } |
752 |
| - |
753 |
| - namestrcpy(&newNameData, newName); |
754 |
| - conform->conname = newNameData; |
755 |
| - |
756 |
| - simple_heap_update(conRel, &tup->t_self, tup); |
757 |
| - CatalogUpdateIndexes(conRel, tup); |
758 |
| - heap_freetuple(tup); |
759 |
| - |
760 |
| - systable_endscan(scan); |
761 |
| - heap_close(conRel, RowExclusiveLock); |
762 |
| - |
763 |
| - /* close relation but hold lock until end of transaction */ |
764 |
| - relation_close(rel, NoLock); |
765 |
| -} |
766 |
| - |
767 |
| - |
768 |
| -/* GetRelationConstraintOid |
769 |
| - * |
770 |
| - * Get the contraint OID by the relation Id of the relation it constraints and |
771 |
| - * this relations' name. We need this function in order to rename a constraint. |
772 |
| - * This is done via "ALTER TABLE ... ALTER CONSTRAINT name" and the parser |
773 |
| - * gives us the relation this constraint is defined on as well as the |
774 |
| - * constraint's name. |
775 |
| - * |
776 |
| - * The function returns: |
777 |
| - * |
778 |
| - * - the unique OID of the constraint if the constraint could be found |
779 |
| - * - the invalid OID if the constraint was not found |
780 |
| - * |
781 |
| - */ |
782 |
| -Oid GetRelationConstraintOid(Oid relId, const char* name) |
783 |
| -{ |
784 |
| - Relation conRel; |
785 |
| - ScanKeyData key[1]; |
786 |
| - SysScanDesc scan; |
787 |
| - HeapTuple tup; |
788 |
| - Oid conId = InvalidOid; |
789 |
| - |
790 |
| - /* we don't change data, so an AccessShareLock is enough */ |
791 |
| - conRel = heap_open(ConstraintRelationId, AccessShareLock); |
792 |
| - |
793 |
| - ScanKeyInit(&key[0], |
794 |
| - Anum_pg_constraint_conrelid, |
795 |
| - BTEqualStrategyNumber, F_OIDEQ, |
796 |
| - ObjectIdGetDatum(relId)); |
797 |
| - |
798 |
| - scan = systable_beginscan(conRel, ConstraintRelidIndexId, true, |
799 |
| - SnapshotNow, 1, key); |
800 |
| - |
801 |
| - while (HeapTupleIsValid((tup = systable_getnext(scan)))) |
802 |
| - { |
803 |
| - Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(tup); |
804 |
| - if (pg_strcasecmp(name, NameStr(con->conname)) == 0) |
805 |
| - { |
806 |
| - conId = HeapTupleGetOid(tup); |
807 |
| - Assert(OidIsValid(conId)); |
808 |
| - } |
809 |
| - } |
810 |
| - |
811 |
| - systable_endscan(scan); |
812 |
| - heap_close(conRel, AccessShareLock); |
813 |
| - |
814 |
| - return conId; |
815 |
| -} |
816 |
| - |
817 |
| - |
818 |
| -/* GetConstraintRelationId |
819 |
| - * |
820 |
| - * Gets the OID of the relation where the constraint is defined on or the |
821 |
| - * invalid OID if the constraint cannot be found. |
822 |
| - */ |
823 |
| -Oid GetConstraintRelationId(Oid conId) |
824 |
| -{ |
825 |
| - Relation conRel; |
826 |
| - ScanKeyData key[1]; |
827 |
| - SysScanDesc scan; |
828 |
| - HeapTuple tup; |
829 |
| - Oid relId = InvalidOid; |
830 |
| - |
831 |
| - /* we don't change data, so an AccessShareLock is enough */ |
832 |
| - conRel = heap_open(ConstraintRelationId, AccessShareLock); |
833 |
| - |
834 |
| - ScanKeyInit(&key[0], |
835 |
| - ObjectIdAttributeNumber, |
836 |
| - BTEqualStrategyNumber, F_OIDEQ, |
837 |
| - ObjectIdGetDatum(conId)); |
838 |
| - |
839 |
| - scan = systable_beginscan(conRel, ConstraintOidIndexId, true, |
840 |
| - SnapshotNow, 1, key); |
841 |
| - |
842 |
| - if (HeapTupleIsValid((tup = systable_getnext(scan)))) |
843 |
| - { |
844 |
| - Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(tup); |
845 |
| - relId = con->conrelid; |
846 |
| - Assert(OidIsValid(relId)); |
847 |
| - } |
848 |
| - |
849 |
| - systable_endscan(scan); |
850 |
| - heap_close(conRel, AccessShareLock); |
851 |
| - |
852 |
| - return relId; |
853 |
| -} |
854 |
| - |
0 commit comments