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

How should I insert array into column in postgresql? #274

Closed
mifopen opened this issue Jul 12, 2019 · 6 comments
Closed

How should I insert array into column in postgresql? #274

mifopen opened this issue Jul 12, 2019 · 6 comments
Labels

Comments

@mifopen
Copy link

mifopen commented Jul 12, 2019

For code

query.AsInsert(new {
    id = "1",
    name = "some",
    ids = new [] { "1", "2", "3" }
})

I get

INSERT INTO "entities"
("id", "name", "ids")
VALUES
($1, $2, $3,$4,$5) -- yes, just without spaces

and
Npgsql.PostgresException (0x80004005): 42601: INSERT has more expressions than target columns

@ahmad-moussawi
Copy link
Contributor

Currently SqlKata doesn't handle non-primitive types on insert/update operations,
adding the ability for RawExpressions can help in this case.

A side question, how are you getting the compiled SQL, since SqlKata doesn't generate symbols like these ones: $1, $2 etc ....

@mifopen
Copy link
Author

mifopen commented Jul 12, 2019

That was a log from Npgsql

@ahmad-moussawi
Copy link
Contributor

Could you please post the log generated from the QueryFactory class https://sqlkata.com/docs/execution/logging?

@mifopen
Copy link
Author

mifopen commented Jul 14, 2019

Of course:

INSERT INTO "tablename" ("id", "name", "ids") VALUES ('1784d656-ce06-4114-b7c3-c86b899ff5de', 'some', '8d8b8ef4-7ba0-49cb-835f-2f40ba56d626','5194ccb5-00b7-4137-9c97-de07bc706d03','15e99f59-cd7c-4ca4-81e8-61ed0b7b0d44')

@ahmad-moussawi
Copy link
Contributor

@mifopen could you please submit a PR with a failed unit test, or post the steps to reproduce the issue, like the create table statement, insert table statement etc... + the Postgres version you are using.
Thanks

@ahmad-moussawi
Copy link
Contributor

ahmad-moussawi commented Sep 29, 2022

as per the Postgres docs https://www.postgresql.org/docs/current/arrays.html
You can insert it as a string enclosed by {} so this should work.

var query = new Query("Table").AsInsert(new {
    Id = "1",
    Values = "{1,2,3}"
});

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

No branches or pull requests

2 participants