Content-Length: 497810 | pFad | http://github.com/timescale/timescaledb/commit/#start-of-content

67BA6D48 Allow tsdb as alias for timescaledb in WITH clauses · timescale/timescaledb@c687fb7 · GitHub
Skip to content

Commit

Permalink
Allow tsdb as alias for timescaledb in WITH clauses
Browse files Browse the repository at this point in the history
This patch allows tsdb as alias for timescaledb in WITH and SET
clauses to save on some typing.
  • Loading branch information
svenklemm committed Feb 22, 2025
1 parent 5fcf4d8 commit c687fb7
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 4 deletions.
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;




0 comments on commit c687fb7

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/timescale/timescaledb/commit/#start-of-content

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy