We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `ckan/migration/versions/067_turn_extras_to_strings.py`
Content:
```
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 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()

```

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:

{"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"}], "after_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 substr(value,0,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 substr(value,0,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"}]}