Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow tsdb as alias for timescaledb in WITH clauses #7765

Merged
merged 1 commit into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .unreleased/pr_7765
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implements: #7765 Allow tsdb as alias for timescaledb in WITH and SET clauses
1 change: 1 addition & 0 deletions src/extension_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#define EXTENSION_NAME "timescaledb" /* Name of the actual extension */
#define EXTENSION_NAMESPACE "timescaledb" /* Namespace for extension objects */
#define EXTENSION_NAMESPACE_ALIAS "tsdb" /* Namespace for extension objects */
#define EXTENSION_FDW_NAME "timescaledb_fdw"
#define TSL_LIBRARY_NAME "timescaledb-tsl"
#define TS_LIBDIR "$libdir/"
Expand Down
4 changes: 3 additions & 1 deletion src/with_clause_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ ts_with_clause_filter(const List *def_elems, List **within_namespace, List **not
{
DefElem *def = (DefElem *) lfirst(cell);

if (def->defnamespace != NULL && pg_strcasecmp(def->defnamespace, EXTENSION_NAMESPACE) == 0)
if (def->defnamespace != NULL &&
(pg_strcasecmp(def->defnamespace, EXTENSION_NAMESPACE) == 0 ||
pg_strcasecmp(def->defnamespace, EXTENSION_NAMESPACE_ALIAS) == 0))
{
if (within_namespace != NULL)
*within_namespace = lappend(*within_namespace, def);
Expand Down
8 changes: 8 additions & 0 deletions tsl/test/expected/cagg_ddl-14.out
Original file line number Diff line number Diff line change
Expand Up @@ -2121,3 +2121,11 @@ SELECT * FROM _timescaledb_catalog.compression_settings;
-------+-----------+---------+--------------+--------------------
(0 rows)

-- test WITH namespace alias
CREATE TABLE with_alias(time timestamptz not null);
CREATE MATERIALIZED VIEW cagg_alias
WITH (tsdb.continuous, tsdb.materialized_only=false) AS
SELECT time_bucket(INTERVAL '1 day', time) FROM conditions GROUP BY 1 WITH NO DATA;
ALTER MATERIALIZED VIEW cagg_alias SET (timescaledb.materialized_only=false);
ALTER MATERIALIZED VIEW cagg_alias SET (tsdb.materialized_only=false);
DROP MATERIALIZED VIEW cagg_alias;
8 changes: 8 additions & 0 deletions tsl/test/expected/cagg_ddl-15.out
Original file line number Diff line number Diff line change
Expand Up @@ -2121,3 +2121,11 @@ SELECT * FROM _timescaledb_catalog.compression_settings;
-------+-----------+---------+--------------+--------------------
(0 rows)

-- test WITH namespace alias
CREATE TABLE with_alias(time timestamptz not null);
CREATE MATERIALIZED VIEW cagg_alias
WITH (tsdb.continuous, tsdb.materialized_only=false) AS
SELECT time_bucket(INTERVAL '1 day', time) FROM conditions GROUP BY 1 WITH NO DATA;
ALTER MATERIALIZED VIEW cagg_alias SET (timescaledb.materialized_only=false);
ALTER MATERIALIZED VIEW cagg_alias SET (tsdb.materialized_only=false);
DROP MATERIALIZED VIEW cagg_alias;
8 changes: 8 additions & 0 deletions tsl/test/expected/cagg_ddl-16.out
Original file line number Diff line number Diff line change
Expand Up @@ -2121,3 +2121,11 @@ SELECT * FROM _timescaledb_catalog.compression_settings;
-------+-----------+---------+--------------+--------------------
(0 rows)

-- test WITH namespace alias
CREATE TABLE with_alias(time timestamptz not null);
CREATE MATERIALIZED VIEW cagg_alias
WITH (tsdb.continuous, tsdb.materialized_only=false) AS
SELECT time_bucket(INTERVAL '1 day', time) FROM conditions GROUP BY 1 WITH NO DATA;
ALTER MATERIALIZED VIEW cagg_alias SET (timescaledb.materialized_only=false);
ALTER MATERIALIZED VIEW cagg_alias SET (tsdb.materialized_only=false);
DROP MATERIALIZED VIEW cagg_alias;
8 changes: 8 additions & 0 deletions tsl/test/expected/cagg_ddl-17.out
Original file line number Diff line number Diff line change
Expand Up @@ -2121,3 +2121,11 @@ SELECT * FROM _timescaledb_catalog.compression_settings;
-------+-----------+---------+--------------+--------------------
(0 rows)

-- test WITH namespace alias
CREATE TABLE with_alias(time timestamptz not null);
CREATE MATERIALIZED VIEW cagg_alias
WITH (tsdb.continuous, tsdb.materialized_only=false) AS
SELECT time_bucket(INTERVAL '1 day', time) FROM conditions GROUP BY 1 WITH NO DATA;
ALTER MATERIALIZED VIEW cagg_alias SET (timescaledb.materialized_only=false);
ALTER MATERIALIZED VIEW cagg_alias SET (tsdb.materialized_only=false);
DROP MATERIALIZED VIEW cagg_alias;
16 changes: 16 additions & 0 deletions tsl/test/expected/compression_ddl.out
Original file line number Diff line number Diff line change
Expand Up @@ -2655,3 +2655,19 @@ SELECT compress_chunk(show_chunks('test_notnull'));

-- broken atm due to bug in default handling in compression
ALTER TABLE test_notnull ALTER COLUMN c2 SET NOT NULL;
-- test alias in parameter name
CREATE TABLE alias(time timestamptz NOT NULL);
SELECT create_hypertable('alias','time');
create_hypertable
---------------------
(48,public,alias,t)
(1 row)

ALTER TABLE alias SET (tsdb.compress, tsdb.compress_orderby='time DESC',tsdb.compress_segmentby='');
INSERT INTO alias SELECT '2025-01-01';
SELECT count(compress_chunk(ch)) FROM show_chunks('alias') ch;
count
-------
1
(1 row)

8 changes: 6 additions & 2 deletions tsl/test/shared/expected/with_clause_parser.out
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ SELECT * FROM test_with_clause_filter(
{"baz", "bar", "foo"},
{"timescaledb", "bar", "baz"},
{"bar", "timescaledb", "baz"},
{"timescaledb", "baz", "bar"}
{"timescaledb", "baz", "bar"},
{"tsdb", "qux", "bar"},
{"tsdb", "quux", "bar"}
}');
namespace | name | value | filtered
-------------+-------------+-------+----------
timescaledb | bar | baz | t
timescaledb | baz | bar | t
tsdb | qux | bar | t
tsdb | quux | bar | t
baz | bar | foo | f
bar | timescaledb | baz | f
(4 rows)
(6 rows)

SELECT * FROM test_with_clause_filter(
'{
Expand Down
4 changes: 3 additions & 1 deletion tsl/test/shared/sql/with_clause_parser.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ SELECT * FROM test_with_clause_filter(
{"baz", "bar", "foo"},
{"timescaledb", "bar", "baz"},
{"bar", "timescaledb", "baz"},
{"timescaledb", "baz", "bar"}
{"timescaledb", "baz", "bar"},
{"tsdb", "qux", "bar"},
{"tsdb", "quux", "bar"}
}');

SELECT * FROM test_with_clause_filter(
Expand Down
10 changes: 10 additions & 0 deletions tsl/test/sql/cagg_ddl.sql.in
Original file line number Diff line number Diff line change
Expand Up @@ -1347,3 +1347,13 @@ SELECT count(compress_chunk(ch)) FROM show_chunks('cagg1') ch;
DROP MATERIALIZED VIEW cagg1;
SELECT * FROM _timescaledb_catalog.compression_settings;

-- test WITH namespace alias
CREATE TABLE with_alias(time timestamptz not null);
CREATE MATERIALIZED VIEW cagg_alias
WITH (tsdb.continuous, tsdb.materialized_only=false) AS
SELECT time_bucket(INTERVAL '1 day', time) FROM conditions GROUP BY 1 WITH NO DATA;

ALTER MATERIALIZED VIEW cagg_alias SET (timescaledb.materialized_only=false);
ALTER MATERIALIZED VIEW cagg_alias SET (tsdb.materialized_only=false);

DROP MATERIALIZED VIEW cagg_alias;
10 changes: 10 additions & 0 deletions tsl/test/sql/compression_ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1153,3 +1153,13 @@ SELECT compress_chunk(show_chunks('test_notnull'));
-- broken atm due to bug in default handling in compression
ALTER TABLE test_notnull ALTER COLUMN c2 SET NOT NULL;

-- test alias in parameter name
CREATE TABLE alias(time timestamptz NOT NULL);
SELECT create_hypertable('alias','time');
ALTER TABLE alias SET (tsdb.compress, tsdb.compress_orderby='time DESC',tsdb.compress_segmentby='');
INSERT INTO alias SELECT '2025-01-01';
SELECT count(compress_chunk(ch)) FROM show_chunks('alias') ch;




Loading