Skip to content

Commit

Permalink
Fixed for ALTER TABLE ALTER COLUMN for Postgres and SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
schuemie committed Apr 10, 2024
1 parent a1d4ab9 commit 6e13c66
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: SqlRender
Type: Package
Title: Rendering Parameterized SQL and Translation to Dialects
Version: 1.17.0
Date: 2024-03-20
Version: 1.17.1
Date: 2024-04-09
Authors@R: c(
person("Martijn", "Schuemie", , "schuemie@ohdsi.org", role = c("aut", "cre")),
person("Marc", "Suchard", role = c("aut"))
Expand All @@ -27,5 +27,5 @@ Suggests:
rmarkdown,
shiny,
shinydashboard
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Encoding: UTF-8
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
SqlRender 1.17.1
================

Bugfixes:

1. For SQLite, now translating `ALTER TABLE ALTER COLUMN BIGINT`to dummy statement (`SELECT 0;`), since all integer types are the same on SQLite.

2. Fixed translation of `ALTER TABLE ALTER COLUMN` on PostgreSQL.


SqlRender 1.17.0
================

Expand Down
4 changes: 2 additions & 2 deletions inst/csv/replacementPatterns.csv
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ postgresql,SELECT DISTINCT TOP @([0-9]+)rows @a;,SELECT DISTINCT @a LIMIT @rows;
postgresql,(SELECT DISTINCT TOP @([0-9]+)rows @a),(SELECT DISTINCT @a LIMIT @rows)
postgresql,"WITH @cte AS (SELECT @s1 '@literal' @s2)","WITH @cte AS (SELECT @s1 CAST('@literal' as TEXT) @s2)"
postgresql,UPDATE STATISTICS @a;,ANALYZE @a;
postgresql,"ALTER TABLE @table ALTER COLUMN @a @b;","ALTER TABLE @table ALTER COLUMN @a TYPE @b;"
postgresql,"ALTER TABLE @table ALTER COLUMN @([^ ]+)a @b;","ALTER TABLE @table ALTER COLUMN @a TYPE @b;"
postgresql,"ALTER TABLE @table ADD @a, @b;","ALTER TABLE @table <token1> @a, <token2> @b;"
postgresql,"<token2> @b, @c;","<token2> @b, <token2> @c;"
postgresql,"ALTER TABLE @table ADD @a;","ALTER TABLE @table <token1> @a;"
Expand Down Expand Up @@ -906,7 +906,7 @@ sqlite,IN (SELECT @a) UNION,IN ((SELECT @a)) UNION
sqlite,(SELECT @a) UNION,SELECT @a UNION
sqlite,UNION (@a),UNION @a
sqlite,UNION ALL (@a),UNION ALL @a
sqlite,"ALTER TABLE @table ALTER COLUMN @a @b;","ALTER TABLE @table ALTER COLUMN @a TYPE @b;"
sqlite,"ALTER TABLE @table ALTER COLUMN @a BIGINT;","SELECT 0;"
sqlite,"ALTER TABLE @table ADD @a, @b;","ALTER TABLE @table ADD @a; ALTER TABLE @table ADD @b;"
hive,...@([0-9]+|y)a,xxx@a
hive,TRY_CAST(@a),CAST(@a)
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-translate-postgresql.R
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,9 @@ test_that("translate sql server -> postgresql ALTER TABLE ADD CONSTRAINT", {
expect_equal_ignore_spaces(sql, "ALTER TABLE cdm.MEASUREMENT ADD CONSTRAINT xpk_MEASUREMENT PRIMARY KEY (measurement_id);")
})

test_that("translate sql server -> postgresql ALTER TABLE ALTER COLUMN", {
sql <- translate("ALTER TABLE my_table ALTER COLUMN a BIGINT;", targetDialect = "postgresql")
expect_equal_ignore_spaces(sql, "ALTER TABLE my_table ALTER COLUMN a TYPE BIGINT;")
})


9 changes: 9 additions & 0 deletions tests/testthat/test-translate-sqlite.R
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,12 @@ test_that("translate sql server -> sqlite ALTER TABLE ADD COLUMN", {
sql <- translate("ALTER TABLE my_table ADD COLUMN a INT;", targetDialect = "sqlite")
expect_equal_ignore_spaces(sql, "ALTER TABLE my_table ADD COLUMN a INT;")
})

test_that("translate sql server -> sqlite ALTER TABLE ALTER COLUMN", {
sql <- translate("ALTER TABLE my_table ALTER COLUMN a BIGINT;", targetDialect = "sqlite")
expect_equal_ignore_spaces(sql, "SELECT 0;")
})




0 comments on commit 6e13c66

Please sign in to comment.