473,761 Members | 9,864 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to get a list of indexes created on a column of a table in postgresql?

3 New Member
Hi All,

I want to know how to get a list of all indexes created on a column of a table in PostgreSQL. There is a program block in our application which do this in oracle, now i want to write the same piece of code which works for PostgreSQL as well. So, i want the list of indexes on a column of a table if i know the column name at that time or list of all the indexes on all the columns of the given table.

Below is the java Code written for Oracle DB, which now i need to rewrite for PostgreSQL. Can any body help me in how retrieve list of indexes as below?
Expand|Select|Wrap|Line Numbers
  1.  /**
  2.      *  Gets a list of all indexes on a given table and column in the mart
  3.      */
  4.     public Vector getIndexList(String column_name, String table_name)
  5.     throws EpiException, EpiSQLException
  6.     {
  7.         Vector indexList = new Vector();
  8.         String sql = "SELECT i.name FROM dbo.sysindexes i WHERE i.name NOT LIKE '[_]%' " +
  9.                     " AND i.name IS NOT NULL AND i.id = " +
  10.                         " (SELECT o.id FROM dbo.sysobjects o " +
  11.                             " WHERE UPPER(o.name) = '" + table_name.toUpperCase() + "') ";
  12.  
  13.         if (column_name != null)
  14.         {
  15.             sql += " AND EXISTS (SELECT 1 FROM dbo.sysindexkeys ik, dbo.syscolumns c " +
  16.                         " WHERE i.indid = ik.indid AND ik.colid = c.colid " +
  17.                         " AND i.id = ik.id AND c.id = ik.id " +
  18.                         " AND UPPER(c.name) = '" + column_name.toUpperCase() + "') ";
  19.         }
  20.         DBConnection con = null;
  21.         DBStatement    stmt = null;
  22.         DBResultSet rs = null;
  23.  
  24.         try
  25.         {
  26.             con = getConnection(this);
  27.             stmt = con.createStatement(this);
  28.             rs = stmt.executeQuery(sql);
  29.  
  30.             while (rs.next())
  31.             {
  32.                 indexList.addElement(rs.getString(1));
  33.             }
  34.         }
  35.         finally
  36.         {
  37.             if (rs != null)
  38.                 rs.close();
  39.             if (stmt != null)
  40.                 stmt.close();
  41.             if (con != null)
  42.                 releaseConnection(con);
  43.         }
  44.         return indexList;
  45.     }
  46.  
Oct 28 '10 #1
1 4435
venkat chitta
3 New Member
I myself found the answer somewhere, posting it here for reference. I am surprise for not answering this question.

String sql = "select i.relname from pg_class t, pg_class i, pg_index ix, pg_attribute a" +
"where t.oid = ix.indrelid and i.oid= ix.indexrelid and a.attrelid = t.oid and a.attnum = ANY(ix.indkey)" +
"and t.relkind = 'r' and t.relname = '" + table_name.toLo werCase() + "'";

if (column_name != null)
{
sql += " AND a.attname = '" + column_name.toL owerCase() + "'";
}
Oct 30 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
5158
by: Peter Foti | last post by:
Hi all, I have a form that contains a 2 column table. In the left column is the description for a particular input (ie - "First Name", "Last Name", "Phone Number", etc.). In the right column is the input element. The left column is right aligned and the right column is left aligned. I would like to replace this table with code that does not use a table for layout, and was hoping someone might be able to help me with the HTML and...
2
5763
by: deepakp | last post by:
Hi, I'm trying to create a site index page. The page layout will consist of a header, left navigation and content display. The left navigation and content display should look like the image file pasted at the bottom of this page http://www.open365test.net/index_test.html I created a stylesheet for the list items as shown at the top of the
2
1940
by: Hymer | last post by:
Hello, I have a small two-column table with three rows. The first column has a logo and the second column has the name of the organization. The logo's in the first column are too high. That is, they don't align horizontally with the organization name. I need to lower the logo's within the column. However, I don't know how to manipulate one column at a time. Everything I
5
2669
by: Hymer | last post by:
Hello, I have a small two-column table with three rows. The first column has a logo and the second column has the name of the organization. The logo's in the first column are too high. That is, they don't align horizontally with the organization name. I need to lower the logo's within the column. However, I don't know how to manipulate one column at a time. Everything I
10
2246
by: ste | last post by:
Hi there, I'm trying to query a MySQL database (containing image data) and to output the results in a HTML table of 3 columns wide (and however many rows it takes) in order to create a basic thumbnail gallery. I can query and output the data as a single column table, but I'm having problems filling up a 3 column table (with different images, looping continuously until the end).
10
2700
by: lesperancer | last post by:
you start with a small application in access97, then you have more modules and more... and you reach the point where tables like 'item' and 'employee' reach the limit and you know there's more indexes required for RI to come does creating a RI programatically instead of the relationship window still consume one of the 32 indexes ? does access2000 / 2003 allow more indexes per table ?
2
13652
by: rcamarda | last post by:
Hi, I found this SQL in the news group to drop indexs in a table. I need a script that will drop all indexes in all user tables of a given database: DECLARE @indexName NVARCHAR(128) DECLARE @dropIndexSql NVARCHAR(4000) DECLARE tableIndexes CURSOR FOR SELECT name FROM sysindexes
6
5532
by: DavidOwens | last post by:
Hey everybody im creating a report for regional managers, i have created a table called STORES, what i want to be able to do is that when the page loads, it currents has the users name n id, but in the days columns mon-sat its empty, and i would like to hace those colums contain drop down lists of the stores from the stores table and save by default when the page next loads, so they dont have to keep going through the dropdown lists. iv...
1
4065
by: akress | last post by:
Hiya, I'm trying to convert a table with 6 colums that looks like this: <table class="myTable" width="640px"> <tr> <td><a href="#"> <img src="../_img/announce.gif" align="middle" border="0"></a> </td> <td><a href="#">
0
9531
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8780
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7332
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5229
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.