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

I want to create array type test data in postgres, but I’m struggling #120

Open
ipposhi39 opened this issue Jan 28, 2022 · 2 comments
Open

Comments

@ipposhi39
Copy link

ipposhi39 commented Jan 28, 2022

I created the following yml file and ran it, but I am getting an error

users.yml

- id: 1
  warehouse_ids:
    - 1
    - 2

error

&testfixtures.InsertError{
  Err: &pq.Error{
    Severity:         "ERROR",
    Code:             "22P02",
    Message:          "malformed array literal: \"[1,2]\"",
    Detail:           "Missing \"]\" after array dimensions.",
    Hint:             "",
    Position:         "",
    InternalPosition: "",
    InternalQuery:    "",
    Where:            "",
    Schema:           "",
    Table:            "",
    Column:           "",
    DataTypeName:     "",
    Constraint:       "",
    File:             "arrayfuncs.c",
    Line:             "292",
    Routine:          "array_in",
  },
   SQL:    "INSERT INTO \"users\" (\"id\", \"warehouse_ids\") VALUES ($1, $2)",
 Params: []interface {}{
    1,
    "[1,2]",
  },
}

How can I solve this?

@aashestakov
Copy link

You can use special prefix:
RAW=
for example, if your column "warehouse_ids" in PostgreSQL has type integer[] (array integer), then in fixture file it is possible to make so:

- id: 1
  warehouse_ids: RAW='{2639,4000}'

this prefix is mentioned in README.md

@andreynering
Copy link
Contributor

Yeah, unfortunately we don't support every column type that exists. Arrays and maps are assumed to be JSON columns. Anything different needs the RAW= prefix currently.

If anyone has an idea for a better syntax, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants