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]: SQL Function does not handle multi-line statements #3092

Closed
1 task
epmenard-ia opened this issue Sep 19, 2024 · 1 comment
Closed
1 task

[Bug]: SQL Function does not handle multi-line statements #3092

epmenard-ia opened this issue Sep 19, 2024 · 1 comment
Labels
bug Used to mark issues with provider's incorrect behavior

Comments

@epmenard-ia
Copy link

epmenard-ia commented Sep 19, 2024

Terraform CLI Version

1.9.4

Terraform Provider Version

0.95.0

Terraform Configuration

resource "snowflake_function" "TEST_PARSER_SQL_FUNC" {
  database = local.databases[var.DATABASE]
  schema = snowflake_schema.TEST_PARSER.name
  name = "SQL_FUNC"

  arguments {
    name = "arg1"
    type = "number"
  }
  comment             = "Example for SQL language"
  return_type         = "VARCHAR(30)"
  null_input_behavior = "CALLED ON NULL INPUT"
  return_behavior     = "VOLATILE"
  statement           = <<-EOT
    select 
      CONCAT('Result: ', arg1 + 1);
 EOT
}

Category

category:resource

Object type(s)

resource:function

Expected Behavior

The query should be able to handle carriage returns and should escape single quotes using a second single quote.

CREATE FUNCTION "DB_DPT_DEV_STG"."TEST_PARSER"."SQL_FUNC" (arg1 NUMBER) RETURNS VARCHAR VOLATILE COMMENT = 'Example for SQL language' AS 'select CONCAT(\'Result: \', arg1 + 1)'

Actual Behavior

request injects newlines

CREATE FUNCTION "DB_DPT_DEV_STG"."TEST_PARSER"."SQL_FUNC" (arg1 NUMBER) RETURNS VARCHAR VOLATILE COMMENT = 'Example for SQL language' AS 'select \n  CONCAT(\'Result: \', arg1 + 1)'
Compilation of SQL UDF failed: SQL compilation error: syntax error line 1 at position 1 unexpected 'select'. syntax error line 2 at position 9 unexpected ''Result: ''. syntax error line 2 at position 29 unexpected ')'.

Steps to Reproduce

  1. Copy configuration
  2. Replace database and schema
  3. Terraform apply

How much impact is this issue causing?

High

Logs

No response

Additional Information

No response

Would you like to implement a fix?

  • Yeah, I'll take it 😎
@epmenard-ia epmenard-ia added the bug Used to mark issues with provider's incorrect behavior label Sep 19, 2024
@epmenard-ia epmenard-ia changed the title [Bug]: SQL Function does not handle multi-line statements and single quotes [Bug]: SQL Function does not handle multi-line statements Sep 19, 2024
@epmenard-ia
Copy link
Author

Nevermind...pitcher's mistake. Turns out the semicolon at the end of the statement was the culprit!!

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

1 participant