Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8688973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:31:04+00:00 2026-06-12T23:31:04+00:00

Is there a way I can remove a constraint based on column names? I

  • 0

Is there a way I can remove a constraint based on column names?

I have postgres 8.4 and when I upgrade my project the upgrade fails because a constraint was named something different in a different version.

Basically, I need to remove a constraint if it exists or I can just remove the constraint using the column names.

The name of the constraint is the only thing that has changed. Any idea if that’s possible?

In this case, I need to remove “patron_username_key”

discovery=# \d patron
                       Table "public.patron"
          Column          |            Type             | Modifiers
--------------------------+-----------------------------+-----------
 patron_id                | integer                     | not null
 create_date              | timestamp without time zone | not null
 row_version              | integer                     | not null
 display_name             | character varying(255)      | not null
 username                 | character varying(255)      | not null
 authentication_server_id | integer                     |
Indexes:
    "patron_pkey" PRIMARY KEY, btree (patron_id)
    "patron_username_key" UNIQUE, btree (username, authentication_server_id)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:31:05+00:00Added an answer on June 12, 2026 at 11:31 pm

    Assuming that unique index is the result of adding a unique constraint, you can use the following SQL statement to remove that constraint:

    do $$
    declare 
      cons_name text;
    begin
      select constraint_name 
         into cons_name
      from information_schema.constraint_column_usage  
      where constraint_schema = current_schema()
      and column_name in ('authentication_server_id', 'username')
      and table_name = 'patron'
      group by constraint_name
      having count(*) = 2;
    
      execute 'alter table patron drop constraint '||cons_name;
    end;
    $$
    

    I’m not sure if this will work if you have “only” added a unique index (instead of a unique constraint).

    If you need to do that for more than 2 columns you also need to adjust the having count(*) = 2 part to match the number of columns in the column_name in .. condition.

    (As you did not specify your PostgreSQL version I’m assuming the current version)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way I can remove the background bar image in the SeekBar
I want to know is there any way that I can remove duplicates from
Is there any way I can remove the small line that appears under tabs
Is there a way I can remove a gist on GitHub? Created a gist
Is there way that I can read the file from remote server using fopen
If someone has deleted the remote branch, is there any way I can pull
Is there any way can declare a bean in just like JSP UseBean in
Is there any way I can set a formatter on models that will convert
Is there any way we can fetch X509 Public Cetrificates using c# from AD
Is there a way I can use one category to stylize all of my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.