prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Postgresql 8.4 error when running paster db init
  When running the paster db init command with the CKAN 2.0 beta, there is an error encountered that appears to be related to use of the left() string function in ckan/migration/versions/067_turn_extras_to_strings.py. According to the documentation and my own simple test, this function is not support in Postgresql 8.4. For a stack trace, see: https://gist.github.com/thriuin/5067819.
  
  Is there a new minimum version of Postgresql required -- documentation still says 8.4 which unfortunately is what comes with RedHat Enterprise.
  
  
  </issue>
  <code>
  [start of ckan/migration/versions/067_turn_extras_to_strings.py]
  1 import json
  2 
  3 def upgrade(migrate_engine):
  4 
  5     with migrate_engine.begin() as connection:
  6         tables = 'package_extra group_extra'
  7         revision_tables = 'package_extra_revision group_extra_revision'
  8 
  9         for table in tables.split():
  10             sql = """select id, value from {table} where left(value,1) = '"' """.format(table=table)
  11             results = connection.execute(sql)
  12             for result in results:
  13                 id, value = result
  14                 update_sql = 'update {table} set value = %s where id = %s'
  15                 connection.execute(update_sql.format(table=table),
  16                                    json.loads(value), id)
  17 
  18         for table in revision_tables.split():
  19             sql = """select id, revision_id, value from {table} where left(value,1) = '"' """.format(table=table)
  20 
  21             results = connection.execute(sql)
  22             for result in results:
  23                 id, revision_id, value = result
  24                 update_sql = 'update {table} set value = %s where id = %s and revision_id = %s'
  25                 connection.execute(update_sql.format(table=table),
  26                                    json.loads(value), id, revision_id)
  27 
  28 
  29
  [end of ckan/migration/versions/067_turn_extras_to_strings.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/ckan/migration/versions/067_turn_extras_to_strings.py b/ckan/migration/versions/067_turn_extras_to_strings.py
  --- a/ckan/migration/versions/067_turn_extras_to_strings.py
  +++ b/ckan/migration/versions/067_turn_extras_to_strings.py
  @@ -7,7 +7,7 @@
           revision_tables = 'package_extra_revision group_extra_revision'
   
           for table in tables.split():
  -            sql = """select id, value from {table} where left(value,1) = '"' """.format(table=table)
  +            sql = """select id, value from {table} where substr(value,0,1) = '"' """.format(table=table)
               results = connection.execute(sql)
               for result in results:
                   id, value = result
  @@ -16,7 +16,7 @@
                                      json.loads(value), id)
   
           for table in revision_tables.split():
  -            sql = """select id, revision_id, value from {table} where left(value,1) = '"' """.format(table=table)
  +            sql = """select id, revision_id, value from {table} where substr(value,0,1) = '"' """.format(table=table)
   
               results = connection.execute(sql)
               for result in results:
  
verification_info: {"golden_diff": "diff --git a/ckan/migration/versions/067_turn_extras_to_strings.py b/ckan/migration/versions/067_turn_extras_to_strings.py\n--- a/ckan/migration/versions/067_turn_extras_to_strings.py\n+++ b/ckan/migration/versions/067_turn_extras_to_strings.py\n@@ -7,7 +7,7 @@\n         revision_tables = 'package_extra_revision group_extra_revision'\n \n         for table in tables.split():\n-            sql = \"\"\"select id, value from {table} where left(value,1) = '\"' \"\"\".format(table=table)\n+            sql = \"\"\"select id, value from {table} where substr(value,0,1) = '\"' \"\"\".format(table=table)\n             results = connection.execute(sql)\n             for result in results:\n                 id, value = result\n@@ -16,7 +16,7 @@\n                                    json.loads(value), id)\n \n         for table in revision_tables.split():\n-            sql = \"\"\"select id, revision_id, value from {table} where left(value,1) = '\"' \"\"\".format(table=table)\n+            sql = \"\"\"select id, revision_id, value from {table} where substr(value,0,1) = '\"' \"\"\".format(table=table)\n \n             results = connection.execute(sql)\n             for result in results:\n", "issue": "Postgresql 8.4 error when running paster db init\nWhen running the paster db init command with the CKAN 2.0 beta, there is an error encountered that appears to be related to use of the left() string function in ckan/migration/versions/067_turn_extras_to_strings.py. According to the documentation and my own simple test, this function is not support in Postgresql 8.4. For a stack trace, see: https://gist.github.com/thriuin/5067819.\n\nIs there a new minimum version of Postgresql required -- documentation still says 8.4 which unfortunately is what comes with RedHat Enterprise.\n\n", "before_files": [{"content": "import json\n\ndef upgrade(migrate_engine):\n\n    with migrate_engine.begin() as connection:\n        tables = 'package_extra group_extra'\n        revision_tables = 'package_extra_revision group_extra_revision'\n\n        for table in tables.split():\n            sql = \"\"\"select id, value from {table} where left(value,1) = '\"' \"\"\".format(table=table)\n            results = connection.execute(sql)\n            for result in results:\n                id, value = result\n                update_sql = 'update {table} set value = %s where id = %s'\n                connection.execute(update_sql.format(table=table),\n                                   json.loads(value), id)\n\n        for table in revision_tables.split():\n            sql = \"\"\"select id, revision_id, value from {table} where left(value,1) = '\"' \"\"\".format(table=table)\n\n            results = connection.execute(sql)\n            for result in results:\n                id, revision_id, value = result\n                update_sql = 'update {table} set value = %s where id = %s and revision_id = %s'\n                connection.execute(update_sql.format(table=table),\n                                   json.loads(value), id, revision_id)\n\n\n", "path": "ckan/migration/versions/067_turn_extras_to_strings.py"}]}