prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Errors when running against the impending sqlalchemy 1.3 release (in beta)
  Originally reported in #667
  
  Datacube consistently fails when run against the current beta version of sqlalchemy. [According to](https://www.sqlalchemy.org/blog/2019/02/08/sqlalchemy-1.3.0b3-released/) the sqlalchemy devs this release "1.3b3 should hopefully be the last beta release for 1.3, as no additional major changes are planned."
  
  This isn't currently a problem, but it will break all of our builds and guides if not resolved before 1.3 is declared stable.
  
  Manually reproduce the error with:
  
  ```
      pip install sqlalchemy==1.3b3
      datacube system init
  ```
  
  - Either the sqlalchemy 1.3 beta has a bug, which we should report to them.
  - Or our own code is doing something incorrect and we should fix it before 1.3 is declared stable.
  
  Errors when running against the impending sqlalchemy 1.3 release (in beta)
  Originally reported in #667
  
  Datacube consistently fails when run against the current beta version of sqlalchemy. [According to](https://www.sqlalchemy.org/blog/2019/02/08/sqlalchemy-1.3.0b3-released/) the sqlalchemy devs this release "1.3b3 should hopefully be the last beta release for 1.3, as no additional major changes are planned."
  
  This isn't currently a problem, but it will break all of our builds and guides if not resolved before 1.3 is declared stable.
  
  Manually reproduce the error with:
  
  ```
      pip install sqlalchemy==1.3b3
      datacube system init
  ```
  
  - Either the sqlalchemy 1.3 beta has a bug, which we should report to them.
  - Or our own code is doing something incorrect and we should fix it before 1.3 is declared stable.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `datacube/drivers/postgres/sql.py`
  Content:
  ```
  1 # coding=utf-8
  2 """
  3 Custom types for postgres & sqlalchemy
  4 """
  5 
  6 from sqlalchemy import TIMESTAMP
  7 from sqlalchemy.dialects.postgresql.ranges import RangeOperators
  8 from sqlalchemy.ext.compiler import compiles
  9 from sqlalchemy.sql import sqltypes
  10 from sqlalchemy.sql.expression import Executable, ClauseElement
  11 from sqlalchemy.sql.functions import GenericFunction
  12 
  13 SCHEMA_NAME = 'agdc'
  14 
  15 
  16 class CreateView(Executable, ClauseElement):
  17     def __init__(self, name, select):
  18         self.name = name
  19         self.select = select
  20 
  21 
  22 @compiles(CreateView)
  23 def visit_create_view(element, compiler, **kw):
  24     return "CREATE VIEW %s AS %s" % (
  25         element.name,
  26         compiler.process(element.select, literal_binds=True)
  27     )
  28 
  29 
  30 TYPES_INIT_SQL = """
  31 create or replace function {schema}.common_timestamp(text)
  32 returns timestamp with time zone as $$
  33 select ($1)::timestamp at time zone 'utc';
  34 $$ language sql immutable returns null on null input;
  35 
  36 create type {schema}.float8range as range (
  37     subtype = float8,
  38     subtype_diff = float8mi
  39 );
  40 """.format(schema=SCHEMA_NAME)
  41 
  42 
  43 # pylint: disable=abstract-method
  44 class FLOAT8RANGE(RangeOperators, sqltypes.TypeEngine):
  45     __visit_name__ = 'FLOAT8RANGE'
  46 
  47 
  48 @compiles(FLOAT8RANGE)
  49 def visit_float8range(element, compiler, **kw):
  50     return "FLOAT8RANGE"
  51 
  52 
  53 # Register the function with SQLAlchemhy.
  54 # pylint: disable=too-many-ancestors
  55 class CommonTimestamp(GenericFunction):
  56     type = TIMESTAMP(timezone=True)
  57     package = 'agdc'
  58     identifier = 'common_timestamp'
  59 
  60     name = '%s.common_timestamp' % SCHEMA_NAME
  61 
  62 
  63 # pylint: disable=too-many-ancestors
  64 class Float8Range(GenericFunction):
  65     type = FLOAT8RANGE
  66     package = 'agdc'
  67     identifier = 'float8range'
  68 
  69     name = '%s.float8range' % SCHEMA_NAME
  70 
  71 
  72 class PGNAME(sqltypes.Text):
  73     """Postgres 'NAME' type."""
  74     __visit_name__ = 'NAME'
  75 
  76 
  77 @compiles(PGNAME)
  78 def visit_name(element, compiler, **kw):
  79     return "NAME"
  80 
  81 
  82 def pg_exists(conn, name):
  83     """
  84     Does a postgres object exist?
  85     :rtype bool
  86     """
  87     return conn.execute("SELECT to_regclass(%s)", name).scalar() is not None
  88 
  89 
  90 def pg_column_exists(conn, table, column):
  91     """
  92     Does a postgres object exist?
  93     :rtype bool
  94     """
  95     return conn.execute("""
  96                         SELECT 1 FROM pg_attribute
  97                         WHERE attrelid = to_regclass(%s)
  98                         AND attname = %s
  99                         AND NOT attisdropped
  100                         """, table, column).scalar() is not None
  101 
  102 
  103 def escape_pg_identifier(engine, name):
  104     """
  105     Escape identifiers (tables, fields, roles, etc) for inclusion in SQL statements.
  106 
  107     psycopg2 can safely merge query arguments, but cannot do the same for dynamically
  108     generating queries.
  109 
  110     See http://initd.org/psycopg/docs/sql.html for more information.
  111     """
  112     # New (2.7+) versions of psycopg2 have function: extensions.quote_ident()
  113     # But it's too bleeding edge right now. We'll ask the server to escape instead, as
  114     # these are not performance sensitive.
  115     return engine.execute("select quote_ident(%s)", name).scalar()
  116
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/datacube/drivers/postgres/sql.py b/datacube/drivers/postgres/sql.py
  --- a/datacube/drivers/postgres/sql.py
  +++ b/datacube/drivers/postgres/sql.py
  @@ -57,7 +57,11 @@
       package = 'agdc'
       identifier = 'common_timestamp'
   
  -    name = '%s.common_timestamp' % SCHEMA_NAME
  +    name = 'common_timestamp'
  +
  +    def __init__(self, *args, **kwargs):
  +        super().__init__(*args, **kwargs)
  +        self.packagenames = ['%s' % SCHEMA_NAME]
   
   
   # pylint: disable=too-many-ancestors
  @@ -66,7 +70,11 @@
       package = 'agdc'
       identifier = 'float8range'
   
  -    name = '%s.float8range' % SCHEMA_NAME
  +    name = 'float8range'
  +
  +    def __init__(self, *args, **kwargs):
  +        super().__init__(*args, **kwargs)
  +        self.packagenames = ['%s' % SCHEMA_NAME]
   
   
   class PGNAME(sqltypes.Text):
  
verification_info: {"golden_diff": "diff --git a/datacube/drivers/postgres/sql.py b/datacube/drivers/postgres/sql.py\n--- a/datacube/drivers/postgres/sql.py\n+++ b/datacube/drivers/postgres/sql.py\n@@ -57,7 +57,11 @@\n     package = 'agdc'\n     identifier = 'common_timestamp'\n \n-    name = '%s.common_timestamp' % SCHEMA_NAME\n+    name = 'common_timestamp'\n+\n+    def __init__(self, *args, **kwargs):\n+        super().__init__(*args, **kwargs)\n+        self.packagenames = ['%s' % SCHEMA_NAME]\n \n \n # pylint: disable=too-many-ancestors\n@@ -66,7 +70,11 @@\n     package = 'agdc'\n     identifier = 'float8range'\n \n-    name = '%s.float8range' % SCHEMA_NAME\n+    name = 'float8range'\n+\n+    def __init__(self, *args, **kwargs):\n+        super().__init__(*args, **kwargs)\n+        self.packagenames = ['%s' % SCHEMA_NAME]\n \n \n class PGNAME(sqltypes.Text):\n", "issue": "Errors when running against the impending sqlalchemy 1.3 release (in beta)\nOriginally reported in #667\r\n\r\nDatacube consistently fails when run against the current beta version of sqlalchemy. [According to](https://www.sqlalchemy.org/blog/2019/02/08/sqlalchemy-1.3.0b3-released/) the sqlalchemy devs this release \"1.3b3 should hopefully be the last beta release for 1.3, as no additional major changes are planned.\"\r\n\r\nThis isn't currently a problem, but it will break all of our builds and guides if not resolved before 1.3 is declared stable.\r\n\r\nManually reproduce the error with:\r\n\r\n```\r\n    pip install sqlalchemy==1.3b3\r\n    datacube system init\r\n```\r\n\r\n- Either the sqlalchemy 1.3 beta has a bug, which we should report to them.\r\n- Or our own code is doing something incorrect and we should fix it before 1.3 is declared stable.\r\n\nErrors when running against the impending sqlalchemy 1.3 release (in beta)\nOriginally reported in #667\r\n\r\nDatacube consistently fails when run against the current beta version of sqlalchemy. [According to](https://www.sqlalchemy.org/blog/2019/02/08/sqlalchemy-1.3.0b3-released/) the sqlalchemy devs this release \"1.3b3 should hopefully be the last beta release for 1.3, as no additional major changes are planned.\"\r\n\r\nThis isn't currently a problem, but it will break all of our builds and guides if not resolved before 1.3 is declared stable.\r\n\r\nManually reproduce the error with:\r\n\r\n```\r\n    pip install sqlalchemy==1.3b3\r\n    datacube system init\r\n```\r\n\r\n- Either the sqlalchemy 1.3 beta has a bug, which we should report to them.\r\n- Or our own code is doing something incorrect and we should fix it before 1.3 is declared stable.\r\n\n", "before_files": [{"content": "# coding=utf-8\n\"\"\"\nCustom types for postgres & sqlalchemy\n\"\"\"\n\nfrom sqlalchemy import TIMESTAMP\nfrom sqlalchemy.dialects.postgresql.ranges import RangeOperators\nfrom sqlalchemy.ext.compiler import compiles\nfrom sqlalchemy.sql import sqltypes\nfrom sqlalchemy.sql.expression import Executable, ClauseElement\nfrom sqlalchemy.sql.functions import GenericFunction\n\nSCHEMA_NAME = 'agdc'\n\n\nclass CreateView(Executable, ClauseElement):\n    def __init__(self, name, select):\n        self.name = name\n        self.select = select\n\n\n@compiles(CreateView)\ndef visit_create_view(element, compiler, **kw):\n    return \"CREATE VIEW %s AS %s\" % (\n        element.name,\n        compiler.process(element.select, literal_binds=True)\n    )\n\n\nTYPES_INIT_SQL = \"\"\"\ncreate or replace function {schema}.common_timestamp(text)\nreturns timestamp with time zone as $$\nselect ($1)::timestamp at time zone 'utc';\n$$ language sql immutable returns null on null input;\n\ncreate type {schema}.float8range as range (\n    subtype = float8,\n    subtype_diff = float8mi\n);\n\"\"\".format(schema=SCHEMA_NAME)\n\n\n# pylint: disable=abstract-method\nclass FLOAT8RANGE(RangeOperators, sqltypes.TypeEngine):\n    __visit_name__ = 'FLOAT8RANGE'\n\n\n@compiles(FLOAT8RANGE)\ndef visit_float8range(element, compiler, **kw):\n    return \"FLOAT8RANGE\"\n\n\n# Register the function with SQLAlchemhy.\n# pylint: disable=too-many-ancestors\nclass CommonTimestamp(GenericFunction):\n    type = TIMESTAMP(timezone=True)\n    package = 'agdc'\n    identifier = 'common_timestamp'\n\n    name = '%s.common_timestamp' % SCHEMA_NAME\n\n\n# pylint: disable=too-many-ancestors\nclass Float8Range(GenericFunction):\n    type = FLOAT8RANGE\n    package = 'agdc'\n    identifier = 'float8range'\n\n    name = '%s.float8range' % SCHEMA_NAME\n\n\nclass PGNAME(sqltypes.Text):\n    \"\"\"Postgres 'NAME' type.\"\"\"\n    __visit_name__ = 'NAME'\n\n\n@compiles(PGNAME)\ndef visit_name(element, compiler, **kw):\n    return \"NAME\"\n\n\ndef pg_exists(conn, name):\n    \"\"\"\n    Does a postgres object exist?\n    :rtype bool\n    \"\"\"\n    return conn.execute(\"SELECT to_regclass(%s)\", name).scalar() is not None\n\n\ndef pg_column_exists(conn, table, column):\n    \"\"\"\n    Does a postgres object exist?\n    :rtype bool\n    \"\"\"\n    return conn.execute(\"\"\"\n                        SELECT 1 FROM pg_attribute\n                        WHERE attrelid = to_regclass(%s)\n                        AND attname = %s\n                        AND NOT attisdropped\n                        \"\"\", table, column).scalar() is not None\n\n\ndef escape_pg_identifier(engine, name):\n    \"\"\"\n    Escape identifiers (tables, fields, roles, etc) for inclusion in SQL statements.\n\n    psycopg2 can safely merge query arguments, but cannot do the same for dynamically\n    generating queries.\n\n    See http://initd.org/psycopg/docs/sql.html for more information.\n    \"\"\"\n    # New (2.7+) versions of psycopg2 have function: extensions.quote_ident()\n    # But it's too bleeding edge right now. We'll ask the server to escape instead, as\n    # these are not performance sensitive.\n    return engine.execute(\"select quote_ident(%s)\", name).scalar()\n", "path": "datacube/drivers/postgres/sql.py"}], "after_files": [{"content": "# coding=utf-8\n\"\"\"\nCustom types for postgres & sqlalchemy\n\"\"\"\n\nfrom sqlalchemy import TIMESTAMP\nfrom sqlalchemy.dialects.postgresql.ranges import RangeOperators\nfrom sqlalchemy.ext.compiler import compiles\nfrom sqlalchemy.sql import sqltypes\nfrom sqlalchemy.sql.expression import Executable, ClauseElement\nfrom sqlalchemy.sql.functions import GenericFunction\n\nSCHEMA_NAME = 'agdc'\n\n\nclass CreateView(Executable, ClauseElement):\n    def __init__(self, name, select):\n        self.name = name\n        self.select = select\n\n\n@compiles(CreateView)\ndef visit_create_view(element, compiler, **kw):\n    return \"CREATE VIEW %s AS %s\" % (\n        element.name,\n        compiler.process(element.select, literal_binds=True)\n    )\n\n\nTYPES_INIT_SQL = \"\"\"\ncreate or replace function {schema}.common_timestamp(text)\nreturns timestamp with time zone as $$\nselect ($1)::timestamp at time zone 'utc';\n$$ language sql immutable returns null on null input;\n\ncreate type {schema}.float8range as range (\n    subtype = float8,\n    subtype_diff = float8mi\n);\n\"\"\".format(schema=SCHEMA_NAME)\n\n\n# pylint: disable=abstract-method\nclass FLOAT8RANGE(RangeOperators, sqltypes.TypeEngine):\n    __visit_name__ = 'FLOAT8RANGE'\n\n\n@compiles(FLOAT8RANGE)\ndef visit_float8range(element, compiler, **kw):\n    return \"FLOAT8RANGE\"\n\n\n# Register the function with SQLAlchemhy.\n# pylint: disable=too-many-ancestors\nclass CommonTimestamp(GenericFunction):\n    type = TIMESTAMP(timezone=True)\n    package = 'agdc'\n    identifier = 'common_timestamp'\n\n    name = 'common_timestamp'\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.packagenames = ['%s' % SCHEMA_NAME]\n\n\n# pylint: disable=too-many-ancestors\nclass Float8Range(GenericFunction):\n    type = FLOAT8RANGE\n    package = 'agdc'\n    identifier = 'float8range'\n\n    name = 'float8range'\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.packagenames = ['%s' % SCHEMA_NAME]\n\n\nclass PGNAME(sqltypes.Text):\n    \"\"\"Postgres 'NAME' type.\"\"\"\n    __visit_name__ = 'NAME'\n\n\n@compiles(PGNAME)\ndef visit_name(element, compiler, **kw):\n    return \"NAME\"\n\n\ndef pg_exists(conn, name):\n    \"\"\"\n    Does a postgres object exist?\n    :rtype bool\n    \"\"\"\n    return conn.execute(\"SELECT to_regclass(%s)\", name).scalar() is not None\n\n\ndef pg_column_exists(conn, table, column):\n    \"\"\"\n    Does a postgres object exist?\n    :rtype bool\n    \"\"\"\n    return conn.execute(\"\"\"\n                        SELECT 1 FROM pg_attribute\n                        WHERE attrelid = to_regclass(%s)\n                        AND attname = %s\n                        AND NOT attisdropped\n                        \"\"\", table, column).scalar() is not None\n\n\ndef escape_pg_identifier(engine, name):\n    \"\"\"\n    Escape identifiers (tables, fields, roles, etc) for inclusion in SQL statements.\n\n    psycopg2 can safely merge query arguments, but cannot do the same for dynamically\n    generating queries.\n\n    See http://initd.org/psycopg/docs/sql.html for more information.\n    \"\"\"\n    # New (2.7+) versions of psycopg2 have function: extensions.quote_ident()\n    # But it's too bleeding edge right now. We'll ask the server to escape instead, as\n    # these are not performance sensitive.\n    return engine.execute(\"select quote_ident(%s)\", name).scalar()\n", "path": "datacube/drivers/postgres/sql.py"}]}