Re: Is there a way to create a functional index that tables tableoidcolumn as an arg? - Mailing list pgsql-general

From Ryan Murphy
Subject Re: Is there a way to create a functional index that tables tableoidcolumn as an arg?
Date
Msg-id CAHeEsBeCchYGrMbZ=f07jMPO6t=WZRY7dvQhgLCTBwOMB0KXXg@mail.gmail.com
Whole thread Raw
In response to Re: Is there a way to create a functional index that tables tableoidcolumn as an arg?  (David Rowley <david.rowley@2ndquadrant.com>)
Responses Re: Is there a way to create a functional index that tables tableoid column as an arg?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi David!  Thanks for the reply.

> tableoid might be an exception to
> this, but it does not really seem like a useful column to index,
> giving it would be indexing the same value for each record in the
> table.

Unless you're using inheritance - then tableoid may vary.  That's the case I'm interested in.
 
-- get all animals that are persons
select ... from animal where tableoid in (select
get_inherited_tables('person'::regclass);

-- get all animals that are not persons
select ... from animal where tableoid not in (select
get_inherited_tables('person'::regclass);


That's a great idea.  I'll try it!
 
Just be careful around search_paths and your use of regclass. In this
case, if "animal" was not in the first schema in search_path, but
someone created another table called "person" that was in the first
schema listed in search_path, then the query would not do what you
want. You might want to consider prefixing the input parameter into
get_inherited_tables with the schema name too.

Good point.

Thanks again!
Ryan

pgsql-general by date:

Previous
From: Thomas Kellerer
Date:
Subject: Re: query_to_xml() returns invalid XML when query returns no rows
Next
From: Tom Lane
Date:
Subject: Re: Is there a way to create a functional index that tables tableoid column as an arg?