RareNCool
RareNCool

Reputation: 436

Can't cast database type tsvector to String

I'm just getting started with PostgreSQL and am trying to perform a full text search. I've got some records in the table, with a column search of type tsvector. That all works great. However, using Npgsql, I'm trying to execute:

using (var cmd = new NpgsqlCommand())
{
    cmd.CommandText = "SELECT search FROM data";
    cmd.Prepare();
    var reader = cmd.ExecuteReader();
}

But I keep getting an InvalidCastException saying

Can't cast database type tsvector to String

I assume there's something more I need to add for it to correctly convert the types, but documentation for NpgSql seems to be virtually non-existent. Is this just not something that can be done, or should I be doing it differently?

Upvotes: 2

Views: 4923

Answers (1)

Sean Stayns
Sean Stayns

Reputation: 4244

I don't have any knowledge of NpgsqlCommand, but have you tried something like this:

var stringResponse= cmd.ExecuteReader().GetString(0);

Upvotes: 2

Related Questions