LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-09-2011, 12:50 PM   #1
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Rep: Reputation: 77
PostgreSQL Can't Rename Table Constraints


I had to rename a table yesterday due to a contact / group name change in the office and sadly I'm the only person who knows how to barely interact with SQL due to my years as a Linux Administrator. Renaming the table was simple:

Code:
iamunix=# ALTER TABLE accounts RENAME TO marketing;
ALTER TABLE
Simple and easy but now I realize all my table constraints are still named with the old table name.

Code:
iamunix=# \d marketing
          Table "public.marketing"
 Column  |         Type          | Modifiers
---------+-----------------------+-----------
 id      | integer               | not null
 vendor  | character varying(40) | not null
 account | integer               | not null
 email   | character varying(40) | not null
 state   | character(2)          | not null
Indexes:
    "accounts_pkey" PRIMARY KEY, btree (id)
    "accounts_account_key" UNIQUE, btree (account)
    "accounts_email_key" UNIQUE, btree (email)
    "accounts_vendor_key" UNIQUE, btree (vendor)
I've searched the web and can't find any SQL example command to rename them. I don't know if the proper procedure is to remove / recreate the constraints or if there actually is a command to do what I want. I can't be the 1st guy to have to rename a table and match the table constraints for organization. My main confusion is that when I create a table from scratch, it auto creates the indexes you see so I have no idea how to edit the constraint.

I do know how to:

Code:
ALTER TABLE foo ALTER COLUMN color DROP NOT NULL;
I just need help renaming the constraints.

Last edited by carlosinfl; 04-09-2011 at 05:48 PM.
 
Old 04-09-2011, 05:49 PM   #2
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Original Poster
Rep: Reputation: 77
Self resolved:

Code:
ALTER INDEX blah RENAME TO meh;
 
Old 04-10-2011, 04:34 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Well done!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't View PostgreSQL Table Data carlosinfl Linux - Server 1 12-11-2010 04:41 PM
Can't insert a record in a table on Postgresql database roqarg Linux - Server 2 09-03-2010 08:36 AM
PHP/MYSQL problem. Rename of table-name solves the problem... mosedrengen Linux - Software 3 01-06-2006 08:07 AM
how do I meet my locale constraints? jonaskoelker Linux - Software 0 08-23-2005 10:06 PM
SuSe 9.1 Password constraints cl2imson Linux - Newbie 3 05-19-2004 11:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration