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

Expecting OBJECT but got VARCHAR when inserting a JSON value. #995

Closed
mattj150 opened this issue Dec 8, 2023 · 3 comments
Closed

Expecting OBJECT but got VARCHAR when inserting a JSON value. #995

mattj150 opened this issue Dec 8, 2023 · 3 comments
Assignees
Labels
question Issue is a usage/other question rather than a bug status-information_needed Additional information is required from the reporter status-triage Issue is under initial triage

Comments

@mattj150
Copy link

mattj150 commented Dec 8, 2023

  1. What version of GO driver are you using? 1.7.0

  2. What operating system and processor architecture are you using? M1 Macbook pro

  3. What version of GO are you using? 1.21.4

  4. Server version: 7.43.0

  5. What did you do?

I am attempting to INSERT a JSON object to an OBJECT column in snowflake. When running the below code I get the following error:

Expression type does not match column data type, expecting OBJECT but got VARCHAR(4) for column object
statement := fmt.Sprintf(`
		INSERT INTO %s (v1,v2,v3,v4,v5,object) 
		VALUES (?, ?, ?, ?, ?, ?)`,
		table)

j, err := json.Marshal("{}")
	if err != nil {
		return err
	}

_, err = db.Exec(statement, v1, v2, v3, v4, v5, string(j))

I didn't see anything in the docs on how to do this correctly, do I need to convert the JSON string to some other type of object?

  1. What did you expect to see?

JSON Object inserted correctly.

@mattj150 mattj150 added the bug Erroneous or unexpected behaviour label Dec 8, 2023
@sfc-gh-dszmolka
Copy link
Contributor

hi and thank you for raising this issue! can you please try to do something like in #217 (comment) (difference is the column type was VARIANT instead of OBJECT but i'm wondering if it works with that as well)

let us know please how it went

@sfc-gh-dszmolka sfc-gh-dszmolka added question Issue is a usage/other question rather than a bug status-triage Issue is under initial triage status-information_needed Additional information is required from the reporter and removed bug Erroneous or unexpected behaviour labels Dec 8, 2023
@sfc-gh-dszmolka sfc-gh-dszmolka self-assigned this Dec 8, 2023
@mattj150
Copy link
Author

mattj150 commented Dec 8, 2023

Hello,
Thanks for the tip, using the above method with TO_OBJECT() worked! Hopefully this thread helps someone else as I didn't find that documented anywhere.

@mattj150 mattj150 closed this as completed Dec 8, 2023
@sfc-gh-dszmolka
Copy link
Contributor

added an example in #999

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issue is a usage/other question rather than a bug status-information_needed Additional information is required from the reporter status-triage Issue is under initial triage
Projects
None yet
Development

No branches or pull requests

2 participants