We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
IndexError when deleting a column
## Description
<!-- A clear and concise description of what the bug is. -->
An indexError occurs when deleting a column through the API. Most of the time the error occurs when deleting the first or second column of a table. Deleting the last columns in a table does not seem to produce this error. 

## Expected behavior
<!-- A clear and concise description of what you expected to happen. -->

- A column should be deleted

## To Reproduce
<!-- How can we recreate this bug? Please try to provide a Minimal, Complete, and Verifiable (http://stackoverflow.com/help/mcve) example if code-related. -->

1. Delete the first  or second column of a table via API. Example: api/v0/tables/1/columns/1/
2. Delete the first or second column of another table via API. Example: api/v0/tables/2/columns/0/

## Screenshots

![Screenshot (35)](https://user-images.githubusercontent.com/66047479/133317146-3e4aa024-afc2-4370-9a79-1007549edccd.png)
![Screenshot (36)](https://user-images.githubusercontent.com/66047479/133317195-0da1725a-9895-4ee3-8b18-90b83eda90c4.png)

## Environment
 - OS: (_eg._ macOS 10.14.6; Fedora 32)
 - Browser: (_eg._ Safari; Firefox)
 - Browser Version: (_eg._ 13; 73)
 - Other info:

## Additional context
<!-- Add any other context about the problem or screenshots here. -->


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `db/columns/operations/select.py`
Content:
```
1 import warnings
2 
3 from sqlalchemy import Table, MetaData, and_, select, text, func
4 
5 from db.tables.operations.select import reflect_table_from_oid
6 from db.utils import execute_statement
7 
8 
9 def get_column_index_from_name(table_oid, column_name, engine, connection_to_use=None):
10     with warnings.catch_warnings():
11         warnings.filterwarnings("ignore", message="Did not recognize type")
12         pg_attribute = Table("pg_attribute", MetaData(), autoload_with=engine)
13     sel = select(pg_attribute.c.attnum).where(
14         and_(
15             pg_attribute.c.attrelid == table_oid,
16             pg_attribute.c.attname == column_name
17         )
18     )
19     result = execute_statement(engine, sel, connection_to_use).fetchone()[0]
20 
21     # Account for dropped columns that don't appear in the SQLAlchemy tables
22     sel = (
23         select(func.count())
24         .where(and_(
25             pg_attribute.c.attisdropped.is_(True),
26             pg_attribute.c.attnum < result,
27         ))
28     )
29     dropped_count = execute_statement(engine, sel, connection_to_use).fetchone()[0]
30 
31     return result - 1 - dropped_count
32 
33 
34 def get_column_default(table_oid, column_index, engine, connection_to_use=None):
35     table = reflect_table_from_oid(table_oid, engine, connection_to_use)
36     column = table.columns[column_index]
37     if column.server_default is None:
38         return None
39 
40     metadata = MetaData()
41     with warnings.catch_warnings():
42         warnings.filterwarnings("ignore", message="Did not recognize type")
43         pg_attribute = Table("pg_attribute", metadata, autoload_with=engine)
44         pg_attrdef = Table("pg_attrdef", metadata, autoload_with=engine)
45 
46     query = (
47         select(pg_attrdef.c.adbin)
48         .select_from(
49             pg_attrdef
50             .join(
51                 pg_attribute,
52                 and_(
53                     pg_attribute.c.attnum == pg_attrdef.c.adnum,
54                     pg_attribute.c.attrelid == pg_attrdef.c.adrelid
55                 )
56             )
57         )
58         .where(and_(
59             pg_attribute.c.attrelid == table_oid,
60             pg_attribute.c.attname == column.name,
61             pg_attribute.c.attnum >= 1,
62         ))
63     )
64 
65     result = execute_statement(engine, query, connection_to_use).first()[0]
66 
67     # Here, we get the 'adbin' value for the current column, stored in the attrdef
68     # system table. The prefix of this value tells us whether the default is static
69     # ('{CONSTANT') or generated ('{FUNCEXPR'). We do not return generated defaults.
70     if result.startswith("{FUNCEXPR"):
71         return None
72 
73     default_textual_sql = column.server_default.arg.text
74     # Defaults are stored as text with SQL casts appended
75     # Ex: "'test default string'::character varying" or "'2020-01-01'::date"
76     # Here, we execute the cast to get the proper python value
77     return execute_statement(engine, select(text(default_textual_sql)), connection_to_use).first()[0]
78
```
--- 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/db/columns/operations/select.py b/db/columns/operations/select.py
--- a/db/columns/operations/select.py
+++ b/db/columns/operations/select.py
@@ -22,6 +22,7 @@
     sel = (
         select(func.count())
         .where(and_(
+            pg_attribute.c.attrelid == table_oid,
             pg_attribute.c.attisdropped.is_(True),
             pg_attribute.c.attnum < result,
         ))

{"golden_diff": "diff --git a/db/columns/operations/select.py b/db/columns/operations/select.py\n--- a/db/columns/operations/select.py\n+++ b/db/columns/operations/select.py\n@@ -22,6 +22,7 @@\n     sel = (\n         select(func.count())\n         .where(and_(\n+            pg_attribute.c.attrelid == table_oid,\n             pg_attribute.c.attisdropped.is_(True),\n             pg_attribute.c.attnum < result,\n         ))\n", "issue": "IndexError when deleting a column\n## Description\r\n<!-- A clear and concise description of what the bug is. -->\r\nAn indexError occurs when deleting a column through the API. Most of the time the error occurs when deleting the first or second column of a table. Deleting the last columns in a table does not seem to produce this error. \r\n\r\n## Expected behavior\r\n<!-- A clear and concise description of what you expected to happen. -->\r\n\r\n- A column should be deleted\r\n\r\n## To Reproduce\r\n<!-- How can we recreate this bug? Please try to provide a Minimal, Complete, and Verifiable (http://stackoverflow.com/help/mcve) example if code-related. -->\r\n\r\n1. Delete the first  or second column of a table via API. Example: api/v0/tables/1/columns/1/\r\n2. Delete the first or second column of another table via API. Example: api/v0/tables/2/columns/0/\r\n\r\n## Screenshots\r\n\r\n![Screenshot (35)](https://user-images.githubusercontent.com/66047479/133317146-3e4aa024-afc2-4370-9a79-1007549edccd.png)\r\n![Screenshot (36)](https://user-images.githubusercontent.com/66047479/133317195-0da1725a-9895-4ee3-8b18-90b83eda90c4.png)\r\n\r\n## Environment\r\n - OS: (_eg._ macOS 10.14.6; Fedora 32)\r\n - Browser: (_eg._ Safari; Firefox)\r\n - Browser Version: (_eg._ 13; 73)\r\n - Other info:\r\n\r\n## Additional context\r\n<!-- Add any other context about the problem or screenshots here. -->\r\n\n", "before_files": [{"content": "import warnings\n\nfrom sqlalchemy import Table, MetaData, and_, select, text, func\n\nfrom db.tables.operations.select import reflect_table_from_oid\nfrom db.utils import execute_statement\n\n\ndef get_column_index_from_name(table_oid, column_name, engine, connection_to_use=None):\n    with warnings.catch_warnings():\n        warnings.filterwarnings(\"ignore\", message=\"Did not recognize type\")\n        pg_attribute = Table(\"pg_attribute\", MetaData(), autoload_with=engine)\n    sel = select(pg_attribute.c.attnum).where(\n        and_(\n            pg_attribute.c.attrelid == table_oid,\n            pg_attribute.c.attname == column_name\n        )\n    )\n    result = execute_statement(engine, sel, connection_to_use).fetchone()[0]\n\n    # Account for dropped columns that don't appear in the SQLAlchemy tables\n    sel = (\n        select(func.count())\n        .where(and_(\n            pg_attribute.c.attisdropped.is_(True),\n            pg_attribute.c.attnum < result,\n        ))\n    )\n    dropped_count = execute_statement(engine, sel, connection_to_use).fetchone()[0]\n\n    return result - 1 - dropped_count\n\n\ndef get_column_default(table_oid, column_index, engine, connection_to_use=None):\n    table = reflect_table_from_oid(table_oid, engine, connection_to_use)\n    column = table.columns[column_index]\n    if column.server_default is None:\n        return None\n\n    metadata = MetaData()\n    with warnings.catch_warnings():\n        warnings.filterwarnings(\"ignore\", message=\"Did not recognize type\")\n        pg_attribute = Table(\"pg_attribute\", metadata, autoload_with=engine)\n        pg_attrdef = Table(\"pg_attrdef\", metadata, autoload_with=engine)\n\n    query = (\n        select(pg_attrdef.c.adbin)\n        .select_from(\n            pg_attrdef\n            .join(\n                pg_attribute,\n                and_(\n                    pg_attribute.c.attnum == pg_attrdef.c.adnum,\n                    pg_attribute.c.attrelid == pg_attrdef.c.adrelid\n                )\n            )\n        )\n        .where(and_(\n            pg_attribute.c.attrelid == table_oid,\n            pg_attribute.c.attname == column.name,\n            pg_attribute.c.attnum >= 1,\n        ))\n    )\n\n    result = execute_statement(engine, query, connection_to_use).first()[0]\n\n    # Here, we get the 'adbin' value for the current column, stored in the attrdef\n    # system table. The prefix of this value tells us whether the default is static\n    # ('{CONSTANT') or generated ('{FUNCEXPR'). We do not return generated defaults.\n    if result.startswith(\"{FUNCEXPR\"):\n        return None\n\n    default_textual_sql = column.server_default.arg.text\n    # Defaults are stored as text with SQL casts appended\n    # Ex: \"'test default string'::character varying\" or \"'2020-01-01'::date\"\n    # Here, we execute the cast to get the proper python value\n    return execute_statement(engine, select(text(default_textual_sql)), connection_to_use).first()[0]\n", "path": "db/columns/operations/select.py"}], "after_files": [{"content": "import warnings\n\nfrom sqlalchemy import Table, MetaData, and_, select, text, func\n\nfrom db.tables.operations.select import reflect_table_from_oid\nfrom db.utils import execute_statement\n\n\ndef get_column_index_from_name(table_oid, column_name, engine, connection_to_use=None):\n    with warnings.catch_warnings():\n        warnings.filterwarnings(\"ignore\", message=\"Did not recognize type\")\n        pg_attribute = Table(\"pg_attribute\", MetaData(), autoload_with=engine)\n    sel = select(pg_attribute.c.attnum).where(\n        and_(\n            pg_attribute.c.attrelid == table_oid,\n            pg_attribute.c.attname == column_name\n        )\n    )\n    result = execute_statement(engine, sel, connection_to_use).fetchone()[0]\n\n    # Account for dropped columns that don't appear in the SQLAlchemy tables\n    sel = (\n        select(func.count())\n        .where(and_(\n            pg_attribute.c.attrelid == table_oid,\n            pg_attribute.c.attisdropped.is_(True),\n            pg_attribute.c.attnum < result,\n        ))\n    )\n    dropped_count = execute_statement(engine, sel, connection_to_use).fetchone()[0]\n\n    return result - 1 - dropped_count\n\n\ndef get_column_default(table_oid, column_index, engine, connection_to_use=None):\n    table = reflect_table_from_oid(table_oid, engine, connection_to_use)\n    column = table.columns[column_index]\n    if column.server_default is None:\n        return None\n\n    metadata = MetaData()\n    with warnings.catch_warnings():\n        warnings.filterwarnings(\"ignore\", message=\"Did not recognize type\")\n        pg_attribute = Table(\"pg_attribute\", metadata, autoload_with=engine)\n        pg_attrdef = Table(\"pg_attrdef\", metadata, autoload_with=engine)\n\n    query = (\n        select(pg_attrdef.c.adbin)\n        .select_from(\n            pg_attrdef\n            .join(\n                pg_attribute,\n                and_(\n                    pg_attribute.c.attnum == pg_attrdef.c.adnum,\n                    pg_attribute.c.attrelid == pg_attrdef.c.adrelid\n                )\n            )\n        )\n        .where(and_(\n            pg_attribute.c.attrelid == table_oid,\n            pg_attribute.c.attname == column.name,\n            pg_attribute.c.attnum >= 1,\n        ))\n    )\n\n    result = execute_statement(engine, query, connection_to_use).first()[0]\n\n    # Here, we get the 'adbin' value for the current column, stored in the attrdef\n    # system table. The prefix of this value tells us whether the default is static\n    # ('{CONSTANT') or generated ('{FUNCEXPR'). We do not return generated defaults.\n    if result.startswith(\"{FUNCEXPR\"):\n        return None\n\n    default_textual_sql = column.server_default.arg.text\n    # Defaults are stored as text with SQL casts appended\n    # Ex: \"'test default string'::character varying\" or \"'2020-01-01'::date\"\n    # Here, we execute the cast to get the proper python value\n    return execute_statement(engine, select(text(default_textual_sql)), connection_to_use).first()[0]\n", "path": "db/columns/operations/select.py"}]}