From 88c801997eb1a6659dfc3fec658209a4698bfa4d Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Sat, 4 Jul 2015 20:16:50 +0200 Subject: [PATCH] Default to a static list of PostgreSQL keywords. In some cases (such as when using a very old PostgreSQL instance or an Amazon Redshift service, as in #255), the function pg_get_keywords() does not exists but we assume that pgloader might still be able to complete its job. We're better off with a static list of keywords than with a unhandled error here, so let's see what happens next with Redshift. --- src/pgsql/queries.lisp | 115 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 112 insertions(+), 3 deletions(-) diff --git a/src/pgsql/queries.lisp b/src/pgsql/queries.lisp index 72c5c59..0d3c0b3 100644 --- a/src/pgsql/queries.lisp +++ b/src/pgsql/queries.lisp @@ -191,10 +191,119 @@ (defun list-reserved-keywords (pgconn) "Connect to PostgreSQL DBNAME and fetch reserved keywords." - (with-pgsql-connection (pgconn) - (pomo:query "select word + (handler-case + (with-pgsql-connection (pgconn) + (pomo:query "select word from pg_get_keywords() - where catcode IN ('R', 'T')" :column))) + where catcode IN ('R', 'T')" :column)) + ;; support for Amazon Redshift + (cl-postgres-error::syntax-error-or-access-violation (e) + ;; 42883 undefined_function + ;; Database error 42883: function pg_get_keywords() does not exist + ;; + ;; the following list comes from a manual query against a local + ;; PostgreSQL server (version 9.5devel), it's better to have this list + ;; than nothing at all. + (declare (ignore e)) + (list "all" + "analyse" + "analyze" + "and" + "any" + "array" + "as" + "asc" + "asymmetric" + "authorization" + "binary" + "both" + "case" + "cast" + "check" + "collate" + "collation" + "column" + "concurrently" + "constraint" + "create" + "cross" + "current_catalog" + "current_date" + "current_role" + "current_schema" + "current_time" + "current_timestamp" + "current_user" + "default" + "deferrable" + "desc" + "distinct" + "do" + "else" + "end" + "except" + "false" + "fetch" + "for" + "foreign" + "freeze" + "from" + "full" + "grant" + "group" + "having" + "ilike" + "in" + "initially" + "inner" + "intersect" + "into" + "is" + "isnull" + "join" + "lateral" + "leading" + "left" + "like" + "limit" + "localtime" + "localtimestamp" + "natural" + "not" + "notnull" + "null" + "offset" + "on" + "only" + "or" + "order" + "outer" + "overlaps" + "placing" + "primary" + "references" + "returning" + "right" + "select" + "session_user" + "similar" + "some" + "symmetric" + "table" + "then" + "to" + "trailing" + "true" + "union" + "unique" + "user" + "using" + "variadic" + "verbose" + "when" + "where" + "window" + "with")))) (defun reset-all-sequences (pgconn &key tables) "Reset all sequences to the max value of the column they are attached to."