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.
This commit is contained in:
Dimitri Fontaine 2018-12-28 10:53:01 +01:00
parent 65d323e4a3
commit b8e8cf7d18
4 changed files with 9 additions and 6 deletions

View File

@ -7,7 +7,10 @@
(in-package #:pgloader.parser)
(defrule view-name (or qualified-table-name maybe-quoted-namestring)
(:identity t))
(:lambda (vn)
(etypecase vn
(cons vn)
(string (cons nil vn)))))
(defrule view-sql (and kw-as dollar-quoted)
(:destructure (as sql) (declare (ignore as)) sql))

View File

@ -229,7 +229,7 @@
(loop :for (name . def) :in views
:for sql := (destructuring-bind (schema . v-name) name
(format nil
"CREATE VIEW ~s.~s AS ~a"
"CREATE VIEW ~@[~s~].~s AS ~a"
schema v-name def))
:do (progn
(log-message :info "MS SQL: ~a" sql)
@ -249,7 +249,7 @@
:do (destructuring-bind (name . def) view-definition
(declare (ignore def))
(format sql
"~@[, ~]~s.~s"
"~@[, ~]~@[~s.~]~s"
(not (zerop i)) (car name) (cdr name)))))))
(log-message :info "PostgreSQL Source: ~a" sql)
(mssql-query sql))))))

View File

@ -10,7 +10,7 @@
(loop :for (name . def) :in views
:for sql := (destructuring-bind (schema . v-name) name
(format nil
"CREATE VIEW ~s.~s AS ~a"
"CREATE VIEW ~@[~s.~]~s AS ~a"
schema v-name def))
:do (progn
(log-message :info "PostgreSQL Source: ~a" sql)
@ -44,7 +44,7 @@
:do (destructuring-bind (name . def) view-definition
(declare (ignore def))
(format sql
"~@[, ~]~s.~s"
"~@[, ~]~@[~s.~]~s"
(not (zerop i)) (car name) (cdr name)))))))
(log-message :info "PostgreSQL Source: ~a" sql)
(pgsql-execute sql))))))

View File

@ -5,7 +5,7 @@ load database
-- including only table names matching 'bits', ~/utilisateur/ in schema 'mysql'
including only table names matching ~/geolocations/ in schema 'public'
materialize views public.some_usps
materialize views some_usps
as $$
select usps, geoid, aland, awater, aland_sqmi, awater_sqmi, location
from districts