From 8476c1a35915b1cf32d1ccfb7b37275bc5e6c99d Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Sun, 20 Mar 2016 20:54:08 +0100 Subject: [PATCH] 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. --- src/pgsql/queries.lisp | 18 +++++++++++++----- test/sakila.load | 7 ++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/pgsql/queries.lisp b/src/pgsql/queries.lisp index b9a2f59..6ccd77e 100644 --- a/src/pgsql/queries.lisp +++ b/src/pgsql/queries.lisp @@ -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." diff --git a/test/sakila.load b/test/sakila.load index 8dd849b..ee85b7a 100644 --- a/test/sakila.load +++ b/test/sakila.load @@ -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,