Skip to content

Commit

Permalink
Provide columns from get_columns() in same order as defined in table (#7
Browse files Browse the repository at this point in the history
)

* Provide columns from get_columns() in same order as defined in table

* Allow bigfiles slip

* Ratchet flake8 metrics
  • Loading branch information
vinceatbluelabs committed Feb 20, 2020
1 parent 9fd50a3 commit 8773a88
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion metrics/bigfiles_high_water_mark
@@ -1 +1 @@
503
506
2 changes: 1 addition & 1 deletion metrics/flake8_high_water_mark
@@ -1 +1 @@
39
32
2 changes: 1 addition & 1 deletion setup.py
@@ -1,7 +1,7 @@
from setuptools import setup
from setuputils import TestCoverageRatchetCommand, VerifyVersionCommand

__version__ = '0.5.4'
__version__ = '0.5.5'
setup(
name='sqlalchemy-vertica-python',
version=__version__,
Expand Down
21 changes: 12 additions & 9 deletions sqla_vertica_python/vertica_python.py
Expand Up @@ -218,26 +218,29 @@ def get_columns(self, connection, table_name, schema=None, **kw):
data_type,
column_default,
is_nullable,
is_identity
is_identity,
ordinal_position
FROM v_catalog.columns
where table_name = '{table_name}'
{schema_conditional}
UNION
UNION
SELECT
column_name,
data_type,
'' as column_default,
true as is_nullable,
false as is_identity
false as is_identity,
ordinal_position
FROM v_catalog.view_columns
where table_name = '{table_name}'
{schema_conditional}
ORDER BY ordinal_position ASC
""".format(table_name=table_name, schema_conditional=schema_conditional)
colobjs = []
column_select_results = list(connection.execute(column_select))
for row in list(connection.execute(column_select)):
sequence_info = connection.execute("""
SELECT
SELECT
sequence_name as name,
minimum as start,
increment_by as increment
Expand All @@ -247,15 +250,15 @@ def get_columns(self, connection, table_name, schema=None, **kw):
""".format(
table_name=table_name,
schema_conditional=(
"" if schema is None
"" if schema is None
else "AND sequence_schema = '{schema}'".format(schema=schema)
)
)
).first() if row.is_identity else None

colobj = self._get_column_info(
row.column_name,
row.data_type,
row.column_name,
row.data_type,
row.is_nullable,
row.column_default,
row.is_identity,
Expand Down Expand Up @@ -294,7 +297,7 @@ def _get_column_info(self, name, data_type, is_nullable, default, is_identity, i
'nullable': is_nullable,
'default': default,
'primary_key': (is_primary_key or is_identity)
}
}
if is_identity:
column_info['autoincrement'] = True
if sequence:
Expand Down Expand Up @@ -365,7 +368,7 @@ def get_pk_constraint(self, connection, table_name, schema=None, **kw):
query = "SELECT constraint_id, constraint_name, column_name FROM v_catalog.constraint_columns \n\
WHERE constraint_type = 'p' AND table_name = '" + table_name + "'"

if schema is not None:
if schema is not None:
query += " AND table_schema = '" + schema + "' \n"

cols = set()
Expand Down

0 comments on commit 8773a88

Please sign in to comment.