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? -
/**
-
* Gets a list of all indexes on a given table and column in the mart
-
*/
-
public Vector getIndexList(String column_name, String table_name)
-
throws EpiException, EpiSQLException
-
{
-
Vector indexList = new Vector();
-
String sql = "SELECT i.name FROM dbo.sysindexes i WHERE i.name NOT LIKE '[_]%' " +
-
" AND i.name IS NOT NULL AND i.id = " +
-
" (SELECT o.id FROM dbo.sysobjects o " +
-
" WHERE UPPER(o.name) = '" + table_name.toUpperCase() + "') ";
-
-
if (column_name != null)
-
{
-
sql += " AND EXISTS (SELECT 1 FROM dbo.sysindexkeys ik, dbo.syscolumns c " +
-
" WHERE i.indid = ik.indid AND ik.colid = c.colid " +
-
" AND i.id = ik.id AND c.id = ik.id " +
-
" AND UPPER(c.name) = '" + column_name.toUpperCase() + "') ";
-
}
-
DBConnection con = null;
-
DBStatement stmt = null;
-
DBResultSet rs = null;
-
-
try
-
{
-
con = getConnection(this);
-
stmt = con.createStatement(this);
-
rs = stmt.executeQuery(sql);
-
-
while (rs.next())
-
{
-
indexList.addElement(rs.getString(1));
-
}
-
}
-
finally
-
{
-
if (rs != null)
-
rs.close();
-
if (stmt != null)
-
stmt.close();
-
if (con != null)
-
releaseConnection(con);
-
}
-
return indexList;
-
}
-
1 4435
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() + "'";
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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
|
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
|
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
|
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).
| |
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 ?
|
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
|
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...
|
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="#">
|
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...
|
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,...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |