You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know if anyone tried this before: I was trying to map the whole table type(aka ROWTYPE) with a .NET class, by doing this:
cmd.CommandText = @"SELECT t.*::""MyTable"" FROM ""MyTable"" t";
Then Npgsql asks me to declare properties for all system columns, no matter I actually use them or not.
Also, #989 makes it almost -- if not -- impossible to do this trick.
IMO, it would be better if Npgsql can recognize ROWTYPE, and if it find a mapped type is a ROWTYPE, it should ignore non-mapped system columns.
If for any reason this can't be done, then providing a base class for mapping ROWTYPE is also acceptable (but this has to be after fixing #989).
Now that tid support has been added, I'm not sure there is anything else to be done here. If there are any other unsupported types, please add specific issues for each one of them. Note that you can also tell Npgsql to request columns with unsupported types as text (see the FAQ), although that might be difficult in your case since * doesn't enforce any ordering.
Am closing for now, please feel free to reopen if needed.
Actually I was asking if there is a way to just ignore the system columns in this case, I want to do this because I don't want to write down every single column's name in the query.
If that's not possible, then providing a base class for ROWTYPE types also helps.
Anyway, I'm going to test if adding tid fixes this out, as soon as I learn how to get the fixed build work.
not working, reports this:
"pg_attributes contains 18 rows for type MyTable, but 12 fields were received!"
It seems that although the system columns are demanded by the type-mapping thing, they are not actually sent to the consumer.
I don't see any possibility fixing this soon.
For now, I can just live with defining additional composite types, but I will seek the possibility to support ROWTYPE mapping.
Can I have a feature request label? Although I don't think it will be ready in the time frame of 3.1
I'm still not clear on what feature exactly you're requesting here... If you don't want PostgreSQL to return system columns, that's a PostgreSQL question rather than an Npgsql question. If your problem is that you're getting columns with unknown types, there's nothing Npgsql can do about that unless you tell it to request these columns (or all columns) as text... Can you please clarify what you need exactly?
cmd.CommandText = @"SELECT t.*::""MyTable"" FROM ""MyTable"" t";
In which "MyTable" is obviously a table name rather than of a regular composite type.
Full story:
The problem is, when I try to map between my .NET class and a ROWTYPE(in which i mean, the composite type of a table itself), Npgsql tells me I need to prepare class members for system columns;
And when I've done what it asked for(via the newest patch which added tid support), it then tells me no such (system) columns included in the returned data (actually, it tells me there are fewer columns than I expected, which I didn't expect, but Npgsql did).
Thus, Npgsql thinks the result set returned by PostgreSQL includes system columns when table names are used like regular composite types for mapping, and it turns out they (system columns) are not included in the data at all.
This happens and only happens if one try to use a table name as composite type, which suppose to be a Npgsql trick but seemly never used in actual development.
I guess this happens might because the metadata Npgsql got from database says ROWTYPEs indeed have system columns, but as we know they are not included in the result in given form of queries, and Npgsql didn't distinguish between ROWTYPEs and regular composite types during some sort of setup phase, the distinguishing part is what I originally intended to ask for.
I tried and want this because I want less hand-write during day-to-day development, I believe more hand-write lead to more mistake, which is also the motive I try composite type mapping in the first place -- but I have to admit it doesn't seem like a convincing reason, as people usually won't try to do this (it seems that I am the only one reported this) , then it should not be a problem for most Npgsql users, it can be a low priority thing.
Activity
Licshee commentedon Mar 13, 2016
hmmm just realize there is a possible quick fixI was wrong
roji commentedon Mar 20, 2016
Now that tid support has been added, I'm not sure there is anything else to be done here. If there are any other unsupported types, please add specific issues for each one of them. Note that you can also tell Npgsql to request columns with unsupported types as text (see the FAQ), although that might be difficult in your case since * doesn't enforce any ordering.
Am closing for now, please feel free to reopen if needed.
Licshee commentedon Mar 21, 2016
Actually I was asking if there is a way to just ignore the system columns in this case, I want to do this because I don't want to write down every single column's name in the query.
If that's not possible, then providing a base class for ROWTYPE types also helps.
Anyway, I'm going to test if adding tid fixes this out, as soon as I learn how to get the fixed build work.
Licshee commentedon Mar 21, 2016
not working, reports this:
"pg_attributes contains 18 rows for type MyTable, but 12 fields were received!"
It seems that although the system columns are demanded by the type-mapping thing, they are not actually sent to the consumer.
I don't see any possibility fixing this soon.
For now, I can just live with defining additional composite types, but I will seek the possibility to support ROWTYPE mapping.
Can I have a feature request label? Although I don't think it will be ready in the time frame of 3.1
roji commentedon Mar 21, 2016
I'm still not clear on what feature exactly you're requesting here... If you don't want PostgreSQL to return system columns, that's a PostgreSQL question rather than an Npgsql question. If your problem is that you're getting columns with unknown types, there's nothing Npgsql can do about that unless you tell it to request these columns (or all columns) as text... Can you please clarify what you need exactly?
Licshee commentedon Mar 21, 2016
TL; DR: try this:
In which "MyTable" is obviously a table name rather than of a regular composite type.
Full story:
The problem is, when I try to map between my .NET class and a ROWTYPE(in which i mean, the composite type of a table itself), Npgsql tells me I need to prepare class members for system columns;
And when I've done what it asked for(via the newest patch which added tid support), it then tells me no such (system) columns included in the returned data (actually, it tells me there are fewer columns than I expected, which I didn't expect, but Npgsql did).
Thus, Npgsql thinks the result set returned by PostgreSQL includes system columns when table names are used like regular composite types for mapping, and it turns out they (system columns) are not included in the data at all.
This happens and only happens if one try to use a table name as composite type, which suppose to be a Npgsql trick but seemly never used in actual development.
I guess this happens might because the metadata Npgsql got from database says ROWTYPEs indeed have system columns, but as we know they are not included in the result in given form of queries, and Npgsql didn't distinguish between ROWTYPEs and regular composite types during some sort of setup phase, the distinguishing part is what I originally intended to ask for.
I tried and want this because I want less hand-write during day-to-day development, I believe more hand-write lead to more mistake, which is also the motive I try composite type mapping in the first place -- but I have to admit it doesn't seem like a convincing reason, as people usually won't try to do this (it seems that I am the only one reported this) , then it should not be a problem for most Npgsql users, it can be a low priority thing.
Emill commentedon Mar 21, 2016
That's kind of smart! But I guess most people would just use an ORM...
http://www.postgresql.org/docs/current/static/catalog-pg-attribute.html tells that the attnum is negative if it is a system column. Such fields should be ignored.
Licshee commentedon Mar 22, 2016
I agree most people won't run into this problem, so I don't demand it to be fixed any soon.
If you are not so interested in fixing this, I will check what I can do, and thanks for your info.
roji commentedon Mar 22, 2016
Reopening, although I doubt I'll have any time to look at this... @Licshee you're welcome to take a stab at it if you want.
roji commentedon May 8, 2016
Looking at this again I think I understand it better. I'll try to take a look soon.
roji commentedon May 8, 2016
Thanks @Emill, I added a filter on attnum and it seem to work now!
Licshee commentedon May 9, 2016
omg it is awesome!