Merge pull request #8032 from ClickHouse/ddl_dictionaries_if_not_exists

Create dictionary if not exists
This commit is contained in:
alesapin 2019-12-04 21:28:05 +03:00 committed by GitHub
commit cfa1b37fd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 3 deletions

View File

@ -849,12 +849,12 @@ bool ParserCreateDictionaryQuery::parseImpl(IParser::Pos & pos, ASTPtr & node, E
return false;
}
if (s_if_not_exists.ignore(pos, expected))
if_not_exists = true;
if (!s_dictionary.ignore(pos, expected))
return false;
if (s_if_not_exists.ignore(pos, expected))
if_not_exists = true;
if (!name_p.parse(pos, name, expected))
return false;

View File

@ -0,0 +1,40 @@
DROP DATABASE IF EXISTS dictdb;
CREATE DATABASE dictdb ENGINE = Ordinary;
CREATE TABLE dictdb.table_for_dict
(
key_column UInt64,
value Float64
)
ENGINE = MergeTree()
ORDER BY key_column;
INSERT INTO dictdb.table_for_dict VALUES (1, 1.1);
CREATE DICTIONARY IF NOT EXISTS dictdb.dict_exists
(
key_column UInt64,
value Float64 DEFAULT 77.77
)
PRIMARY KEY key_column
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_for_dict' DB 'dictdb'))
LIFETIME(1)
LAYOUT(FLAT());
SELECT dictGetFloat64('dictdb.dict_exists', 'value', toUInt64(1));
CREATE DICTIONARY IF NOT EXISTS dictdb.dict_exists
(
key_column UInt64,
value Float64 DEFAULT 77.77
)
PRIMARY KEY key_column
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_for_dict' DB 'dictdb'))
LIFETIME(1)
LAYOUT(FLAT());
SELECT dictGetFloat64('dictdb.dict_exists', 'value', toUInt64(1));
DROP DATABASE IF EXISTS dictdb;