dropping anonymous constraints

dropping anonymous constraints

Post by Ben Libl » Thu, 18 Jul 2002 13:06:28



Given a table "data" with column "value", one can add a constraint that
has no name:

     ALTER TABLE data ADD CHECK (value > 0);

How, then, does one remove this constraint?  The "ALTER TABLE ... DROP
CONSTRAINT ..." command expects to see a constraint name, but this
constraint is anonymous.

---------------------------(end of broadcast)---------------------------

 
 
 

dropping anonymous constraints

Post by Tom La » Thu, 18 Jul 2002 14:13:10



> Given a table "data" with column "value", one can add a constraint that
> has no name:
>      ALTER TABLE data ADD CHECK (value > 0);
> How, then, does one remove this constraint?

The constraint *does* have a name, it's just an auto-assigned one
(probably of the form "$n").  Try psql's \d command to check out
constraint names.

                        regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

 
 
 

dropping anonymous constraints

Post by Ben Libl » Thu, 18 Jul 2002 17:17:03



> Try psql's \d command to check out constraint names.

That did it.  Thank you for the speedy reply.

(I can't help but shake my head at the design of ALTER TABLE's constraint
manipulation facilities, whose non-orthogonality requires one to step
outside the language and use things like "\d" to accomplish this sort of
task.  Perhaps when I have more database experience under my belt that
will feel like less of a kludge.)

In any case, thanks again for the help!

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

 
 
 

dropping anonymous constraints

Post by Doug McNaug » Thu, 18 Jul 2002 23:09:06




> > Try psql's \d command to check out constraint names.

> That did it.  Thank you for the speedy reply.

> (I can't help but shake my head at the design of ALTER TABLE's constraint
> manipulation facilities, whose non-orthogonality requires one to step
> outside the language and use things like "\d" to accomplish this sort of
> task.  Perhaps when I have more database experience under my belt that
> will feel like less of a kludge.)

'\d' and friends in psql are just shorthand for queries against the
system catalogs.  So you're not "stepping outside the language",
really.  

If you do 'psql -E' you can see the queries generated by the various
backslash commands.

-Doug

---------------------------(end of broadcast)---------------------------

 
 
 

dropping anonymous constraints

Post by Ben Libl » Fri, 19 Jul 2002 04:59:52



> '\d' and friends in psql are just shorthand for queries against the
> system catalogs.  So you're not "stepping outside the language",
> really.

But the system catalogs' names and organization are themselves
PostgreSQL specific.  Presumably MySQL and Oracle and the other folks
don't have tables named "pg_relcheck", "pg_class", and so on.  They
probably provide the same facilities, but not in the same way.

I guess this is the part I find suprising: the non-standardization of
database meta-information.  SQL is great for getting information *out*
of a database, but seems to have a serious blind spot when it comes to
fetching information *about* a database.

{shrug}

In any case, thanks for the "psql -E" tip!

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

 
 
 

dropping anonymous constraints

Post by Neil Conw » Fri, 19 Jul 2002 05:25:57



> I guess this is the part I find suprising: the non-standardization of
> database meta-information.  SQL is great for getting information *out*
> of a database, but seems to have a serious blind spot when it comes to
> fetching information *about* a database.

No, there are INFORMATION_SCHEMA views defined by SQL -- someone will
get around to implementing them one of these days.

The problem here is that (a) not everyone implements the SQL standard
views (b) the SQL standard stuff doesn't include PostgreSQL extensions,
obviously.

Cheers,

Neil

--

PGP Key ID: DB3C29FC

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html

 
 
 

1. Can't Drop a Constraint w/o Knowing the Constraint Name

I'm trying to drop a constraint and then add a contraint
to the same table.  The problem is that I don't know the
name of the the constraint (yes, poor planning) but, I
have to offer a script as a solution.  I know how to get
the name of the contraint:

SELECT CONSTRAINT_NAME
  FROM INFORMATION_SCHEMA.TAB
 WHERE table_name = 'tableName'

And, I know how to drop a contraint:

Alter table tableName drop constraint constraintName

But, I can't figure out how to nest the select statement
in the drop statement w/o getting an error:

Alter table tableName DROP CONSTRAINT (SELECT
CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE table_name = 'tableName')

I, also, tried to use local variables and assign the

the drop statement.  Still no can do.

Any ideas?

2. New England Informix Grp Mtg

3. ALTER TABLE: how to replace an anonymous constraint

4. RAID Question

5. HOWTO: Drop article from anonymous pull subscription?

6. Attn SQL Server Gurus.... sp running slow when called from the app

7. Drop Constraint

8. VA-Herndon-92792--C-SQL-UNIX-Programmer Analyst

9. How do I drop constraints using sp?

10. Dropping Constraint

11. drop columns with default constraints

12. Please Help dropping constraint

13. Drop Tables Foreign Key Constraints