Skip to content

Commit b8e8cf7

Browse files
committed
Fix bugs in the recent extended support for materialized views.
Materialized views without an explicit schema name are supported, but then would raise an error when trying to use destructuring-bind on a string rather than the (cons schema-name table-name). This patch fixes that.
1 parent 65d323e commit b8e8cf7

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

src/parsers/command-materialize-views.lisp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
(in-package #:pgloader.parser)
88

99
(defrule view-name (or qualified-table-name maybe-quoted-namestring)
10-
(:identity t))
10+
(:lambda (vn)
11+
(etypecase vn
12+
(cons vn)
13+
(string (cons nil vn)))))
1114

1215
(defrule view-sql (and kw-as dollar-quoted)
1316
(:destructure (as sql) (declare (ignore as)) sql))

src/sources/mssql/mssql-schema.lisp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@
229229
(loop :for (name . def) :in views
230230
:for sql := (destructuring-bind (schema . v-name) name
231231
(format nil
232-
"CREATE VIEW ~s.~s AS ~a"
232+
"CREATE VIEW ~@[~s~].~s AS ~a"
233233
schema v-name def))
234234
:do (progn
235235
(log-message :info "MS SQL: ~a" sql)
@@ -249,7 +249,7 @@
249249
:do (destructuring-bind (name . def) view-definition
250250
(declare (ignore def))
251251
(format sql
252-
"~@[, ~]~s.~s"
252+
"~@[, ~]~@[~s.~]~s"
253253
(not (zerop i)) (car name) (cdr name)))))))
254254
(log-message :info "PostgreSQL Source: ~a" sql)
255255
(mssql-query sql))))))

src/sources/pgsql/pgsql-schema.lisp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
(loop :for (name . def) :in views
1111
:for sql := (destructuring-bind (schema . v-name) name
1212
(format nil
13-
"CREATE VIEW ~s.~s AS ~a"
13+
"CREATE VIEW ~@[~s.~]~s AS ~a"
1414
schema v-name def))
1515
:do (progn
1616
(log-message :info "PostgreSQL Source: ~a" sql)
@@ -44,7 +44,7 @@
4444
:do (destructuring-bind (name . def) view-definition
4545
(declare (ignore def))
4646
(format sql
47-
"~@[, ~]~s.~s"
47+
"~@[, ~]~@[~s.~]~s"
4848
(not (zerop i)) (car name) (cdr name)))))))
4949
(log-message :info "PostgreSQL Source: ~a" sql)
5050
(pgsql-execute sql))))))

test/pgsql-source.load

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ load database
55
-- including only table names matching 'bits', ~/utilisateur/ in schema 'mysql'
66
including only table names matching ~/geolocations/ in schema 'public'
77

8-
materialize views public.some_usps
8+
materialize views some_usps
99
as $$
1010
select usps, geoid, aland, awater, aland_sqmi, awater_sqmi, location
1111
from districts

0 commit comments

Comments
 (0)