{% macro CREATE_TYPE_SQL(conn, type_name, type_length, type_precision, is_type_array) %}
{% if type_name.startswith('time') and type_length %}
{#############################################################}
{###### Need to check against separate time types - START ######}
{#############################################################}
{% if type_name == "timestamp without time zone" %}
timestamp({{ type_length }}) without time zone{% elif type_name == "timestamp with time zone" %}
timestamp({{ type_length }}) with time zone{% elif type_name == "time without time zone" %}
time({{ type_length }}) without time zone{% elif type_name == "time with time zone" %}
time({{ type_length }}) with time zone{% endif %}{% if is_type_array %}
[]{% endif %}
{#############################################################}
{###### Need to check against separate time types - END ######}
{#############################################################}
{% else %}
{{ conn|qtTypeIdent(type_name) }}{% if type_length %}
({{ type_length }}{% if type_precision%}, {{ type_precision }}{% endif %}){% endif %}{% if is_type_array %}
[]{% endif %}
{% endif %}
{% endmacro %}
{######################################################}
{##### BELOW MACRO IS USED FOR COLUMN TYPE UPDATE #####}
{######################################################}
{% macro UPDATE_TYPE_SQL(conn, data, o_data) %}
{% if data.cltype and data.cltype.startswith('time') and data.attlen %}
{#############################################################}
{###### Need to check against separate time types - START ######}
{#############################################################}
{% if data.cltype == "timestamp without time zone" %}
timestamp({{ data.attlen }}) without time zone {% elif data.cltype == "timestamp with time zone" %}
timestamp({{ data.attlen }}) with time zone {% elif data.cltype == "time without time zone" %}
time({{ data.attlen }}) without time zone {% elif data.cltype == "time with time zone" %}
time({{ data.attlen }}) with time zone {% endif %}{% if data.hasSqrBracket %}[]{% endif %}
{#############################################################}
{# if only type changes, we need to give previous length to current type#}
{#############################################################}
{% elif data.cltype and data.cltype.startswith('time') and o_data.attlen != 'None' %}
{% if data.cltype == "timestamp without time zone" %}
timestamp({{ o_data.attlen }}) without time zone {% elif data.cltype == "timestamp with time zone" %}
timestamp({{ o_data.attlen }}) with time zone {% elif data.cltype == "time without time zone" %}
time({{ o_data.attlen }}) without time zone {% elif data.cltype == "time with time zone" %}
time({{ o_data.attlen }}) with time zone {% endif %}{% if data.hasSqrBracket %}[]{% endif %}
{#############################################################}
{# if only length changes, we need to give previous length to current type#}
{#############################################################}
{% elif data.attlen and o_data.cltype.startswith('time') %}
{% if o_data.cltype == "timestamp without time zone" %}
timestamp({{ data.attlen }}) without time zone {% elif o_data.cltype == "timestamp with time zone" %}
timestamp({{ data.attlen }}) with time zone {% elif o_data.cltype == "time without time zone" %}
time({{ data.attlen }}) without time zone {% elif o_data.cltype == "time with time zone" %}
time({{ data.attlen }}) with time zone {% endif %}{% if o_data.hasSqrBracket %}[]{% endif %}
{###### Need to check against separate time types - END ######}
{% elif (data.cltype and not data.cltype.startswith('time')) or not o_data.cltype.startswith('time') %}
{#############################################################}
{########## We will create SQL for other types here ##########}
{#############################################################}
{% if data.cltype %}{{conn|qtTypeIdent(data.cltype)}} {% elif o_data.typnspname != 'pg_catalog' %}{{conn|qtTypeIdent(o_data.typnspname, o_data.cltype)}}{% else %}{{conn|qtTypeIdent(o_data.cltype)}} {% endif %}{% if (data.attlen and data.attlen != 'None') or (data.attprecision and data.attprecision != 'None') %}
{% if data.attlen and data.attlen != 'None' %}
({{ data.attlen }}{% elif data.attprecision and data.attprecision != 'None' %}({{ o_data.attlen }}{% endif %}{% if data.attprecision and data.attprecision != 'None' %}
, {{ data.attprecision }}){% elif o_data.attprecision and o_data.attprecision != 'None' %}, {{ o_data.attprecision }}){% else %}){% endif %}
{% endif %}
{% endif %}
{% endmacro %}