简体   繁体   中英

operator does not exist: @ timestamp without time zone

In a parameterized query issued from c# code to PostgreSQL 10.14 via dotConnect 7.7.832 .NET connector, I select either a parameter value or the local timestamp, if the parameter is NULL:

using (var cmd = new PgSqlCommand("select COALESCE(@eventTime, LOCALTIMESTAMP)", connection)

When executed, this statement throws the error in subject. If I comment out the corresponding parameter

cmd.Parameters.Add("@eventTime", PgSqlType.TimeStamp).Value = DateTime.Now;

and hardcode

using (var cmd = new PgSqlCommand("select COALESCE('11/6/2020 2:36:58 PM', LOCALTIMESTAMP)", connection)

or if I cast the parameter

using (var cmd = new PgSqlCommand("select COALESCE(cast(@eventTime as timestamp without time zone), LOCALTIMESTAMP)", connection)

then it works. Can anyone explain what @ operator in the error is referring to and why the error?

In the case that doesn't work, your .Net connection library seems to be passing an SQL command containing a literal @ to the database, rather than substituting it. The database assumes you are trying to use @ as a user defined operator, as it doesn't know what else it could possibly be. But no such operator has been defined.

Why is it doing that? I have no idea. That is a question about your .Net connection library, not about PostgreSQL itself, so you might want to add tag.

The error message you get from the database should include the text of the query it received (as opposed to the text you think it was sent) and it is often useful to see that in situations like this. If that text is not present in the client's error message (some connection libraries do not faithfully pass this info along) you should be able to pull it directly from the PostgreSQL server's log file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM