我正在尝试使用NHibernate命名参数执行参数化的“upsert”查询,但我得到了一个异常。语法似乎是正确的,但它仍在抛出:
NHibernate.Exceptions.GenericADOException was unhandled by user code
HResult=-2146232832
Message=could not execute native bulk manipulation query: ...
InnerException:
BaseMessage=syntax error at or near "ON"
Code=42601
ErrorCode=-2147467259
File=scan.l
HResult=-2147467259
InternalPosition=0
Line=1053
Message=42601: syntax error at or near "ON"
MessageText=syntax error at or near "ON"
Position=536
Routine=scanner_yyerror
Severity=ERROR
Source=Npgsql
SqlState=42601
StackTrace:
at Npgsql.NpgsqlConnector.DoReadMessage(DataRowLoadingMode dataRowLoadingMode, Boolean isPrependedMessage)
at Npgsql.NpgsqlConnector.ReadMessageWithPrepended(DataRowLoadingMode dataRowLoadingMode)
at Npgsql.NpgsqlConnector.ReadExpecting[T]()
at Npgsql.NpgsqlDataReader.NextResultInternal()
at Npgsql.NpgsqlDataReader.NextResult()
at Npgsql.NpgsqlCommand.Execute(CommandBehavior behavior)
at Npgsql.NpgsqlCommand.ExecuteNonQueryInternal()
at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
at NHibernate.Engine.Query.NativeSQLQueryPlan.PerformExecuteUpdate(QueryParameters queryParameters, ISessionImplementor session)
InnerException:
据我所知,根据PostgreSQL文档,语法是正确的:https://www.postgresql.org/docs/9.5/static/sql-insert.html
insert into session (session_expiry,
session_last_page,
session_fbr_lh_state,
session_user_id,
session_user_guid,
session_user_name,
session_user_fname,
session_image_url,
session_user_balance,
session_user_url_profile,
session_user_cloud_name,
session_last_qty,
session_email,
session_utm_source,
session_utm_campaign,
session_utm_medium,
session_user_agent,
session_guid) VALUES (
:session_expiry,
:session_last_page,
:session_fbr_lh_state,
:session_user_id,
:session_user_guid,
:session_user_name,
:session_user_fname,
:session_image_url,
:session_user_balance,
:session_user_url_profile,
:session_user_cloud_name,
:session_last_qty,
:session_email,
:session_utm_source,
:session_utm_campaign,
:session_utm_medium,
:session_user_agent,
:session_guid )
ON CONFLICT DO UPDATE SET session_expiry = :session_expiry,
session_last_page = :session_last_page,
session_fbr_lh_state = :session_fbr_lh_state,
session_user_id = :session_user_id,
session_user_guid = :session_user_guid,
session_user_name = :session_user_name,
session_user_fname = :session_user_fname,
session_image_url = :session_image_url,
session_user_balance = :session_user_balance,
session_user_url_profile = :session_user_url_profile,
session_user_cloud_name = :session_user_cloud_name,
session_last_qty = :session_last_qty,
session_email = :session_email,
session_utm_source = :session_utm_source,
session_utm_campaign = :session_utm_campaign,
session_utm_medium = :session_utm_medium,
session_user_agent = :session_user_agent
dbModel.CreateSQLQuery(SESSION_UPSERT)
.SetParameter("session_guid", data.SessionId)
.SetParameter("session_expiry", data.SessionExpiration)
.SetParameter("session_last_page", data.SessionLastPage)
.SetParameter("session_fbr_lh_state", data.SessionFbrLhState)
.SetParameter("session_user_id", data.SessionUserId)
.SetParameter("session_user_guid", data.SessionUserGuid)
.SetParameter("session_user_name", data.SessionUserName)
.SetParameter("session_user_fname", data.SessionUserFname)
.SetParameter("session_image_url", data.SessionUserImageurl)
.SetParameter("session_user_balance", data.SessionUserBalance)
.SetParameter("session_user_url_profile", data.SessionUserUrlProfile)
.SetParameter("session_user_cloud_name", data.SessionUserReferralCloudName)
.SetParameter("session_last_qty", data.SessionLastQty)
.SetParameter("session_email", data.SessionEmail)
.SetParameter("session_utm_source", data.SessionUtmSource)
.SetParameter("session_utm_campaign", data.SessionUtmCampaign)
.SetParameter("session_utm_medium", data.SessionUtmMedium)
.SetParameter("session_user_agent", data.SessionUserAgent)
.ExecuteUpdate();
答案 0 :(得分:0)
我回答了自己的问题。不得不更新到PostgreSQL v9.5。卫生署!