Search code examples
postgresqlchunkstimescaledb

Timescaledb - How to display chunks of a hypertable in a specific schema


I have a table named conditions on a schema named test. I created a hypertable and inserted hundreds of rows.

When I run select show_chunks(), it works and displays chunks but I cannot use the table name as parameter as suggested in the manual. This does not work:

SELECT show_chunks("test"."conditions");

How can I fix this?

Ps: I want to query the chunk itself by its name? How can I do this?


Solution

  • The show_chunks expects a regclass, which depending on your current search path means you need to schema qualify the table.

    The following should work:

    SELECT public.show_chunks('test.conditions');
    

    The double quotes are only necessary if your table is a delimited identifier, for example if your tablename contains a space, you would need to add the double quotes for the identifier. You will still need to wrap it in single quotes though:

    SELECT public.show_chunks('test."equipment conditions"');
    SELECT public.show_chunks('"test schema"."equipment conditions"');
    

    For more information about identifier quoting: https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

    Edit: Addressing the PS:

    I want to query the chunk itself by its name? How can I do this?

    feike=# SELECT public.show_chunks('test.conditions');
                    show_chunks                 
    --------------------------------------------
     _timescaledb_internal._hyper_28_1176_chunk
     _timescaledb_internal._hyper_28_1177_chunk
    [...]
    
    SELECT * FROM _timescaledb_internal._hyper_28_1176_chunk;