Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Can't add expression column to table #3095

Closed
1 task
lorenzo-romanelli opened this issue Sep 20, 2024 · 4 comments
Closed
1 task

[Bug]: Can't add expression column to table #3095

lorenzo-romanelli opened this issue Sep 20, 2024 · 4 comments
Assignees
Labels
bug Used to mark issues with provider's incorrect behavior

Comments

@lorenzo-romanelli
Copy link

Terraform CLI Version

opentofu 1.7.2

Terraform Provider Version

0.96.0

Terraform Configuration

column {
    name     = "_TS_CREATED"
    nullable = false
    type     = "TIMESTAMP_TZ"
    comment  = "The timestamp when the record was created."
    default {
      expression = "CURRENT_TIMESTAMP()"
    }
  }

Category

category:resource

Object type(s)

resource:table

Expected Behavior

A column _TS_CREATED is created, and its default value should be the output of the CURRENT_TIMESTAMP() expression.

Actual Behavior

apply fails with the following error:

╷
│ Error: failed to add column _TS_CREATED => Only adding a column as a constant is supported by Snowflake
│ 
│   with snowflake_table.user_tenants,
│   on settings_data.tf line 154, in resource "snowflake_table" "user_tenants":
│  154: resource "snowflake_table" "user_tenants" {
│ 
╵

Steps to Reproduce

  1. Create a snowflake_table resource which includes a column with a default block with an expression inside
  2. Run apply

How much impact is this issue causing?

Low

Logs

No response

Additional Information

No response

Would you like to implement a fix?

  • Yeah, I'll take it 😎
@lorenzo-romanelli lorenzo-romanelli added the bug Used to mark issues with provider's incorrect behavior label Sep 20, 2024
@sfc-gh-jmichalak
Copy link
Collaborator

Hi @lorenzo-romanelli 👋

Snowflake does not support adding new columns with default expressions (see docs).

@lorenzo-romanelli
Copy link
Author

Hi @sfc-gh-jmichalak thank for the quick feedback!

To clarify, we are not trying to add a column to an existing table, but to create a new table which includes the column with a default expression. Looking at the doc it should be possible?
https://docs.snowflake.com/en/sql-reference/sql/create-table

@sfc-gh-jmichalak
Copy link
Collaborator

sfc-gh-jmichalak commented Sep 20, 2024

Yes, it should be possible, and we even have a test case for this :) But the message you got is returned only in the update function, so that shouldn't happen.
Please provide the whole table configuration and logs with TF_LOG=DEBUG.

@lorenzo-romanelli
Copy link
Author

My bad, we overlooked something in the process 😅 Destroying the table and recreating it works as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Used to mark issues with provider's incorrect behavior
Projects
None yet
Development

No branches or pull requests

2 participants