snowflakedb / gosnowflake

Go Snowflake Driver
Apache License 2.0
294 stars 122 forks source link

SNOW-1524204: Session Variables passed as connection params are ignored #1173

Closed OrCh3n closed 2 months ago

OrCh3n commented 3 months ago
  1. What version of GO driver are you using? v1.7.2

  2. What operating system and processor architecture are you using? darwin/arm64

  3. What version of GO are you using? 1.21.8

4.Server version:* E.g. 1.90.1 You may get the server version by running a query: 8.24.1

  1. What did you do?
        sfCfg = &gosnowflake.Config{
            <account, user etc.>
            Params: map[string]*string{"$customer_id": lo.ToPtr("test")}
        }
        url, _ = gosnowflake.DSN(sfCfg)
        // open the db using the url
                // execute SHOW VARIABLES -> nothing shows
  2. What did you expect to see? as per the docs https://docs.snowflake.com/en/sql-reference/session-variables there should be a session variable named CUSTOMER_ID.

The issue is the $ is url encoded, so when parsing the config back from the url it is left url encoded, while it needs to be a $ sign. ParseDSN should decode the parameter keys IMO.

sfc-gh-dszmolka commented 3 months ago

hey, thanks for raising this ! so the Params field is supposed to contain only connection and session parameters , hence the name. Please see this doc for reference.

if you're trying to use a session variable , which can be indeed be anything, can you please try specifying them per the documentation you linked; using the SET statement after establishing the connection? For example, SET customer_id='test'

sfc-gh-dszmolka commented 3 months ago

ah, nevermind, I see now what you're referring to - JDBC is already supporting this notation you mentioned.

sfc-gh-dszmolka commented 3 months ago

as you mentioned, the session variable indeed comes urlencoded

        "SESSION_PARAMETERS": {
            "%24CUSTOMER_ID": "test",
            "CLIENT_VALIDATE_DEFAULT_PARAMETERS": true
        },

and thus never actually recognized as a session variable, by the server. As a workaround, please consider using the method mentioned previously while we work on this enhancement for the driver to be on par with the JDBC driver regarding this aspect.

sfc-gh-dszmolka commented 2 months ago

hopefully https://github.com/snowflakedb/gosnowflake/pull/1177 can address this. Thank you again for pointing this gap out !

OrCh3n commented 2 months ago

Thanks for the quick response!

sfc-gh-dszmolka commented 2 months ago

fix PR is now merged and will be part of the next upcoming release

sfc-gh-dszmolka commented 2 months ago

released with gosnowflake v1.11.0 in July 2024