Skip to content
Advertisement

How to SELECT data from a postgreSQL INDEX?

If I created an index with following command: CREATE INDEX ixname ON tbname (id);

Where ixname is the name of index, tbname is the table name for which the index is being created and id is the column the index is for.

Now, if I wanted to view what’s in ixname, how would I do it? (I’m asking with the assumption that an index is a relation/table with sorted column)

Advertisement

Answer

You just can’t. Not as a client, not using SQL.

Data in the index is internal to PostgreSQL, and it’s not accessible to the outside world. You can introspect your index definitions (using pg_indexes table or pg_get_indexdef function), but you can’t look up what’s actually stored in those.

Well, you technically can find the file(s) in which the index data is stored (use pg_class.relfilenode and checking for files in base/ subdirectory), and decode the binary data of their b-trees (or whatever your indexes use), but I’m not sure this is what you want to do. Unless you intend to learn or hack PostgreSQL internals.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement