dbTalk Databases Forums  

Textual representation of expression/partial indexes?

comp.databases.postgresql comp.databases.postgresql


Discuss Textual representation of expression/partial indexes? in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Michael Schuerig
 
Posts: n/a

Default Textual representation of expression/partial indexes? - 04-15-2009 , 08:12 AM







I'd like to get a textual SQL representation of expression and partial
indexes. I've found that the information is somehow contained in
pg_index indexprs and indpred, but apparently in parsed form. There
obviously is a way to get back an SQL representation, pgadmin3 does it,
but how?

Michael

--
Michael Schuerig
mailto:michael (AT) schuerig (DOT) de
http://www.schuerig.de/michael/


Reply With Quote
  #2  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: Textual representation of expression/partial indexes? - 04-15-2009 , 08:22 AM






Michael Schuerig <michael (AT) schuerig (DOT) de> wrote:
Quote:
I'd like to get a textual SQL representation of expression and partial
indexes. I've found that the information is somehow contained in
pg_index indexprs and indpred, but apparently in parsed form. There
obviously is a way to get back an SQL representation, pgadmin3 does it,
but how?
see pg_indexes, column indexdef. Or use pg_get_indexdef(index_oid).

Andreas
--
Andreas Kretschmer
Linux - weil ich es mir wert bin!
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net


Reply With Quote
  #3  
Old   
Michael Schuerig
 
Posts: n/a

Default Re: Textual representation of expression/partial indexes? - 04-15-2009 , 09:06 AM



Andreas Kretschmer wrote:

Quote:
Michael Schuerig <michael (AT) schuerig (DOT) de> wrote:

I'd like to get a textual SQL representation of expression and
partial indexes. I've found that the information is somehow contained
in pg_index indexprs and indpred, but apparently in parsed form.
There obviously is a way to get back an SQL representation, pgadmin3
does it, but how?

see pg_indexes, column indexdef. Or use pg_get_indexdef(index_oid).
Thanks, I stopped when I found pg_index and didn't notice pg_indexes.

Michael

--
Michael Schuerig
mailto:michael (AT) schuerig (DOT) de
http://www.schuerig.de/michael/



Reply With Quote
  #4  
Old   
Michael Schuerig
 
Posts: n/a

Default Re: Textual representation of expression/partial indexes? - 04-15-2009 , 12:44 PM



Andreas Kretschmer wrote:

Quote:
Michael Schuerig <michael (AT) schuerig (DOT) de> wrote:

I'd like to get a textual SQL representation of expression and
partial indexes. I've found that the information is somehow contained
in pg_index indexprs and indpred, but apparently in parsed form.
There obviously is a way to get back an SQL representation, pgadmin3
does it, but how?

see pg_indexes, column indexdef. Or use pg_get_indexdef(index_oid).
I have been a bit sloppy in my wording. I get what I asked for, but not
in exactly the form I want:

SELECT DISTINCT i.relname, d.indisunique, c.i,
CASE WHEN d.indkey[c.i] = 0 THEN NULL
ELSE a.attname
END,
pg_get_indexdef(i.oid, c.i + 1, true) AS column_def,
pg_get_indexdef(i.oid, 0, true) AS index_def
FROM pg_class AS i
JOIN pg_index AS d ON d.indexrelid = i.oid
JOIN pg_class AS t ON t.oid = d.indrelid
JOIN pg_attribute AS a ON (a.attrelid = t.oid)
JOIN generate_series(0, 9) AS c(i) ON d.indkey[c.i] IN (a.attnum, 0)
WHERE t.relname = 'people'
AND t.relnamespace IN
(SELECT oid FROM pg_namespace WHERE nspname IN ('public'))
AND d.indisprimary = 'f'
ORDER BY i.relname, c.i;

For a partial index, I can extract the WHERE clause from the result I
get from pg_get_indexdef(indexoid, 0, true) -- but do I have to?

Michael

--
Michael Schuerig
mailto:michael (AT) schuerig (DOT) de
http://www.schuerig.de/michael/



Reply With Quote
Reply




Thread Tools
Display Modes

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

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.