Skip to content

Commit

Permalink
Merge pull request #3850 from masatake/sql--create-view-if-not-exists
Browse files Browse the repository at this point in the history
 SQL: extact views in "create view if not exists VIEW ..."
  • Loading branch information
masatake authored Nov 21, 2023
2 parents f727e74 + 5a65c08 commit e0dcf65
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
messages_data input.sql /^CREATE VIEW IF NOT EXISTS messages_data AS$/;" V
21 changes: 21 additions & 0 deletions Units/parser-sql.r/sql-create-view-if-not-exists.d/input.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Taken from leapp-0.15.1/res/schema/audit-layout.sql

CREATE VIEW IF NOT EXISTS messages_data AS
SELECT
message.id AS id,
message.context AS context,
message.stamp AS stamp,
message.topic AS topic,
message.type AS type,
data_source.actor AS actor,
data_source.phase AS phase,
msg_data.hash AS message_hash,
msg_data.data AS message_data,
host.hostname AS hostname
FROM
message
JOIN
data_source ON data_source.id = message.data_source_id,
message_data AS msg_data ON message.message_data_hash = msg_data.hash,
host ON host.id = data_source.host_id
;
5 changes: 5 additions & 0 deletions parsers/sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -2752,10 +2752,15 @@ static void parseView (tokenInfo *const token)
* create view VIEW;
* create view VIEW as ...;
* create view VIEW (...) as ...;
* create view if not exists VIEW as ...;
* -- [SQLITE] https://www.sqlite.org/lang_createview.html
*/

readIdentifier (name);
readToken (token);

parseIdAfterIfNotExists(name, token, false);

if (isType (token, TOKEN_PERIOD))
{
readIdentifier (name);
Expand Down

0 comments on commit e0dcf65

Please sign in to comment.