Allow setting search_path with multiple schemas.

The PostgreSQL search_path allows multiple schemas and might even need
it to be able to reference types and other tables. Allow setting more
than one schema by using the fact that PostgreSQL schema names don't
need to be individually quoted, and passing down the exact content of
the SET search_path value down to PostgreSQL.

Fix #359.
This commit is contained in:
Dimitri Fontaine 2016-03-20 20:54:08 +01:00
parent 63c3b3b1c7
commit 8476c1a359
2 changed files with 17 additions and 8 deletions

View File

@ -170,11 +170,19 @@
"Set given GUCs to given values for the current session."
(let ((pomo:*database* (or database pomo:*database*)))
(loop
for (name . value) in alist
for set = (format nil "SET~:[~; LOCAL~] ~a TO '~a'" transaction name value)
do
(log-message :debug set)
(pomo:execute set))))
:for (name . value) :in alist
:for set := (cond
((string-equal "search_path" name)
;; for search_path, don't quote the value
(format nil "SET~:[~; LOCAL~] ~a TO ~a"
transaction name value))
(t
;; general case: quote the value
(format nil "SET~:[~; LOCAL~] ~a TO '~a'"
transaction name value)))
:do (progn ; indent helper
(log-message :debug set)
(pomo:execute set)))))
(defun pgsql-connect-and-execute-with-timing (pgconn section label sql &key (count 1))
"Run pgsql-execute-with-timing within a newly establised connection."

View File

@ -9,10 +9,11 @@ load database
WITH concurrency = 1, workers = 6
SET maintenance_work_mem to '128MB', work_mem to '12MB', search_path to 'sakila'
SET maintenance_work_mem to '128MB',
work_mem to '12MB',
search_path to 'sakila, public, "$user"'
CAST -- type datetime to timestamptz drop default drop not null using zero-dates-to-null,
type date drop not null drop default using zero-dates-to-null,
CAST type date drop not null drop default using zero-dates-to-null,
type datetime to timestamp drop default drop not null using zero-dates-to-null
-- type tinyint to boolean using tinyint-to-boolean,