Le 20/11/2010 16:09, Guillaume Lelarge a écrit : > Le 20/11/2010 15:15, Michael Shapiro a écrit : >> Theoretically, you could have the same problem with the primary key -- there >> could be an index with that name already. > > If it happens, it would be PostgreSQL fault, not pgAdmin. The name of > the constraint and the name of the index, in a primary key and in a > unique contraint, are determined by PostgreSQL, not pgAdmin. On the > contrario, the name of the index of a foreign key is determined by > pgAdmin because this is not a PostgreSQL feature. > >> But in practice it doesn't happen. You could generate a name for the foreign >> key based on similar pattern for the pk >> and if it fails, then it falls on the user to provide a name. Seem like it >> would work 99% of the time. >> > > I guess Magnus's idea is the good one (fk_tablename_columnname). >
The issue in this idea is that you can have more than one column in a foreignkey. Yes, I know we can put all of them till we reach 63 characters. But it feels quite a burden. The simple patch attached forces one to type either the constraint name or the index name. Which seems enough for me. Any new objections? :) -- Guillaume http://www.postgresql.fr http://dalibo.com
>From 5b8bebb9bdd30ea48cb257c976198ce2b8b35851 Mon Sep 17 00:00:00 2001 From: Guillaume Lelarge <guilla...@lelarge.info> Date: Sat, 20 Nov 2010 18:43:19 +0100 Subject: [PATCH] Force typing the constraint name or the index name Before this patch, the index name stays "fki_" without a constraint name. If someone tries to create two foreign keys without typing a constraint name or an index name, the second one will fail. So, we force typing either of them. Fixes #289. --- pgadmin/dlg/dlgForeignKey.cpp | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/pgadmin/dlg/dlgForeignKey.cpp b/pgadmin/dlg/dlgForeignKey.cpp index ec7d970..8f77df5 100644 --- a/pgadmin/dlg/dlgForeignKey.cpp +++ b/pgadmin/dlg/dlgForeignKey.cpp @@ -82,6 +82,9 @@ dlgForeignKey::dlgForeignKey(pgaFactory *f, frmMain *frame, ctlListView *colList wxString dlgForeignKey::DefaultIndexName(const wxString &name) { + if (name.IsEmpty()) + return wxEmptyString; + if (name.Left(3) == wxT("fk_")) return wxT("fki_") + name.Mid(3); else if (name.Left(3) == wxT("FK_")) -- 1.7.1
-- Sent via pgadmin-support mailing list (pgadmin-support@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgadmin-support