5

In Oracle, MySQL I can select from partition

SELECT ... FROM ... PARTITION (...)

In SQL Server syntax is a bit different involving partitioning function.

is there a way to do it in PostgreSQL?

thank you!

2
  • SELECT * FROM product where tableoid::regclass::text ='product_a' Commented Nov 8, 2014 at 16:13
  • SELECT t.* FROM product t JOIN pg_class c ON c.oid = t.tableoid JOIN pg_namespace n ON c.relnamespace = n.oid WHERE t.tableoid=16411 Commented Nov 8, 2014 at 16:14

1 Answer 1

4

PostgreSQL provided partitioning through table inheritance.

Partitions are child tables with an unique name like any other table, so you just select from them directly with their names. The only special case is for the parent table: to select data from the parent table ignoring the child tables, an additional keyword ONLY is used as in SELECT * FROM ONLY parent_table.

Example from the manual:

CREATE TABLE measurement_y2006m02 (
    CHECK ( logdate >= DATE '2006-02-01' AND logdate < DATE '2006-03-01' )
) INHERITS (measurement);

So select * from measurement_y2006m02 would get data from only this partition.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, I can actually use it.
is there some way to call the parent table?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.