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

[Doc]: Item types supported for arrays #80

Open
natalie-o-perret opened this issue Feb 19, 2021 · 7 comments
Open

[Doc]: Item types supported for arrays #80

natalie-o-perret opened this issue Feb 19, 2021 · 7 comments

Comments

@natalie-o-perret
Copy link

Steps to reproduce

I've been reading about array, and I was wondering if there was a list of the item types supported for array and ranges:

I can't find any... I mean the documentation can make you imagine that you can actually define an array or arrays or arrays of IP Address... which I doubt can work. It's very likely only 1D arrays, right?

But reading a further it gets a little fuzzy:

Some talk about multi dimensional arrays... others just 1D arrays of a given base type... it's all confusing, so I would like to what is supported

The issue

No clear documentation about what types are supported as array items.

Further technical details

Npgsql version: 5.0.1.1
PostgreSQL version: PostgreSQL 10.5 (Ubuntu 10.5-2.pgdg16.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609, 64-bit
Operating system: (Client) Microsoft Windows 10 Enterprise

@roji roji transferred this issue from npgsql/npgsql Feb 19, 2021
@roji
Copy link
Member

roji commented Feb 19, 2021

We should indeed provide a bit of documentation.

At the ADO level, Npgsql supports all the array capabilities of PostgreSQL itself, so in general what you find in the PostgreSQL docs is supported. Note that PostgreSQL does not support arrays of arrays, but does support multi-dimensional arrays (you can see some examples in the docs). You can use either .NET arrays or generic Lists to map to PostgreSQL arrays.

Note, however, that the EF Core provider's multi-dimensional arrays support is very limited - basically stick to one-dimensional arrays.

@natalie-o-perret
Copy link
Author

Note that PostgreSQL does not support arrays of arrays, but does support multi-dimensional arrays (you can see some examples in the docs). You can use either .NET arrays or generic Lists to map to PostgreSQL arrays.

@roji Hey thanks for your answer! Much appreciated!

One thing though, when you're saying:

Note that PostgreSQL does not support arrays of arrays, but does support multi-dimensional arrays (you can see some examples in the docs)

How does it work in npgsql to benefit from the multidimensional array support then?

NpgsqlDbType.Array | NpgsqlDbType.Array | NpgsqlDbType.SmallInt

@roji
Copy link
Member

roji commented Feb 20, 2021

Nope, just NpgsqlDbType.Array | NpgsqlDbType.SmallInt. That corresponds to an array of any dimensions in PostgreSQL.

@natalie-o-perret
Copy link
Author

natalie-o-perret commented Feb 20, 2021

Nope, just NpgsqlDbType.Array | NpgsqlDbType.SmallInt. That corresponds to an array of any dimensions in PostgreSQL.

@roji Alright, that's a little bit counterintuitive... just to make this super-duper clear, with NpgsqlDbType.Array | NpgsqlDbType.SmallInt, you can pass resp. int[], int [,], int[,,], int[,,,] and even bigger dimensions?

@roji
Copy link
Member

roji commented Feb 20, 2021

Yes. I know it may seem a bit odd, but the way PostgreSQL handles type arrays, all arrays of a given element type - regardless of dimension - are of a single type; this is why a single NpgsqlDbType value maps to them all.

@roji
Copy link
Member

roji commented Feb 20, 2021

BTW regardless of PostgreSQL, NpgsqlDbType.Array | NpgsqlDbType.Array | NpgsqlDbType.SmallInt doesn't really make any sense in C# - ORing something will itself doesn't produce any useful effect.

@natalie-o-perret
Copy link
Author

natalie-o-perret commented Feb 20, 2021

@roji alrite alrite, thanks! It makes sense now.

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

2 participants