A few weeks ago I updated my driver from 5.30.172 to the current one. Ok, after 3 years without updating I expected that there will be problems. A few of them I could resolve by reading the changelog.
But now I have a problem with PgSqlLoader. I use SetValue(), but I can't set the primary key id (integer type). I found out that the primary key column (serial type) is not in the list of columns in the PgSqlLoader object. Is this a bug or a feature? And is there a workaround? I don't want to let the database set the primary key in this case.
Thank you in advance.
PgSqlLoader primary key column
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: PgSqlLoader primary key column
The reason of this behavior is that the Serial type is an autoincrement type, and value is not required for a column of such type when inserting records. If such a column is created in the Columns collection, it would require setting values for it, because passing NULL value will cause an error. That's why columns of the type Serial are not added to the Columns collection when calling the CreateColumns method of the PgSqlLoader class.
If you want to specify values for a Serial column manually, you need to add this column to the Columns collection manually:
If you want to specify values for a Serial column manually, you need to add this column to the Columns collection manually:
Code: Select all
PgSqlConnection conn = new PgSqlConnection("connection string");
conn.Open();
PgSqlLoader loader = new PgSqlLoader();
loader.Connection = conn;
loader.TableName = "loader";
loader.CreateColumns();
loader.Columns.Add("column name", PgSqlType.Int, 10, 10, 0);
loader.Open();
Re: PgSqlLoader primary key column
I already thought that the reason of this behaviour is the serial type of the column.
The workaround is fine, thank you!
The workaround is fine, thank you!