Compare commits

...

1 Commits

Author SHA1 Message Date
Claire Carroll
7ca4881b37 wip: add ordinal position to Column class 2020-11-18 11:01:33 -05:00
3 changed files with 12 additions and 5 deletions

View File

@@ -20,6 +20,7 @@ class Column(JsonSchemaMixin):
char_size: Optional[int] = None
numeric_precision: Optional[Any] = None
numeric_scale: Optional[Any] = None
ordinal_position: Optional[int] = None
@classmethod
def translate_type(cls, dtype: str) -> str:
@@ -38,6 +39,10 @@ class Column(JsonSchemaMixin):
def quoted(self) -> str:
return '"{}"'.format(self.column)
@property
def ordinal_position(self) -> int:
return self.ordinal_position
@property
def data_type(self) -> str:
if self.is_string():

View File

@@ -39,7 +39,8 @@
data_type,
character_maximum_length,
numeric_precision,
numeric_scale
numeric_scale,
ordinal_position
from {{ relation.information_schema('columns') }}
where table_name = '{{ relation.identifier }}'
@@ -121,7 +122,7 @@
Postgres tables have a maximum length off 63 characters, anything longer is silently truncated.
Temp relations add a lot of extra characters to the end of table namers to ensure uniqueness.
To prevent this going over the character limit, the base_relation name is truncated to ensure
that name + suffix + uniquestring is < 63 characters.
that name + suffix + uniquestring is < 63 characters.
#}
{% macro postgres__make_temp_relation(base_relation, suffix) %}
{% set dt = modules.datetime.datetime.now() %}

View File

@@ -86,7 +86,8 @@
data_type,
character_maximum_length,
numeric_precision,
numeric_scale
numeric_scale,
ordinal_position
from information_schema."columns"
where table_name = '{{ relation.identifier }}'
@@ -121,7 +122,8 @@
SPLIT_PART(REGEXP_SUBSTR(col_type, '[0-9,]+'), ',', 2),
'')::int
else null
end as numeric_scale
end as numeric_scale,
col_num as ordinal_position
from pg_get_late_binding_view_cols()
cols(view_schema name, view_name name, col_name name,
@@ -254,4 +256,3 @@
{% macro redshift__alter_column_comment(relation, column_dict) %}
{% do return(postgres__alter_column_comment(relation, column_dict)) %}
{% endmacro %}