timescale / timescaledb

An open-source time-series SQL database optimized for fast ingest and complex queries. Packaged as a PostgreSQL extension.
https://www.timescale.com/
Other
16.89k stars 853 forks source link

[Bug]: Cannot create hypertable when set search_path to false #6875

Closed tingyi-suger closed 2 months ago

tingyi-suger commented 2 months ago

What type of bug is this?

Incorrect result, Unexpected error

What subsystems and features are affected?

Command processing, Query executor

What happened?

CREATE TABLE usage_record_group ( id character varying(36) NOT NULL, creation_time timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL );

select create_hypertable('metering.usage_record_group', by_range('creation_time'));

When set the `search_path` to false, it will report error

ERROR: function by_range(unknown) does not exist LINE 1: ... create_hypertable('usage_record_group', by_range('... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.


* Note: it runs well in the timescale cloud environment.

### TimescaleDB version affected

timescale/timescaledb-ha:pg16

### PostgreSQL version used

16

### What operating system did you use?

Docker

### What installation method did you use?

Docker

### What platform did you run on?

Not applicable

### Relevant log output and stack trace

_No response_

### How can we reproduce the bug?

```bash
1. run command

docker run -d --name timescaledb -p 5432:5432 -e POSTGRES_PASSWORD=password timescale/timescaledb-ha:pg16
  1. exec container
    psql -U postgres -h localhost
  2. run script
    
    SELECT pg_catalog.set_config('search_path', '', false);

CREATE TABLE usage_record_group ( id character varying(36) NOT NULL, creation_time timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL );

select create_hypertable('metering.usage_record_group', by_range('creation_time'));

antekresic commented 2 months ago

I'm sorry, I don't see any unexpected behavior here. If you empty your search path, create_hypertable function needs to be referred via the schema it resides in _timescaledb_functions.

In that case, this should work:

select _timescaledb_functions.create_hypertable('metering.usage_record_group', by_range('creation_time'));

Hope this helps!