{# Snowflake SELECT used by jdbc_source_snowflake instances.
   Required template variables:
     snowflake_database     e.g. "FACTS"
     snowflake_schema       e.g. "QA"
     snowflake_table        e.g. "LABEL_PARTICIPANT"
     columns                list[str] or None — if None, emits `*` with a cast on timestamp_column_name
     timestamp_column_name  e.g. "CREATED_AT" — cast to TIMESTAMP_NTZ in the SELECT
     where_clause           optional raw SQL WHERE body (without the `WHERE` keyword)

   Note: TIMESTAMP_NTZ cast is required when the watermark column is TIMESTAMP_TZ or TIMESTAMP_LTZ
   in Snowflake — the JDBC source connector handles TIMESTAMP_NTZ most reliably.
#}
SELECT
{%- if columns %}
{%- for col in columns %}
    {{ col }}{% if col == timestamp_column_name %}::TIMESTAMP_NTZ AS {{ col }}{% endif %}{% if not loop.last %},{% endif %}
{%- endfor %}
{%- else %}
    *,
    {{ timestamp_column_name }}::TIMESTAMP_NTZ AS {{ timestamp_column_name }}
{%- endif %}
FROM {{ snowflake_database }}.{{ snowflake_schema }}.{{ snowflake_table }}
{%- if where_clause %}
WHERE {{ where_clause }}
{%- endif %}
