相关疑难解决方法(0)

heroku,postgreSQL,django,comments,tastypie:没有运算符匹配给定的名称和参数类型.您可能需要添加显式类型转换

我对django的内置注释模型进行了简单的查询,并使用heroku的postgreSQL数据库获取下面的错误:

DatabaseError: operator does not exist: integer = text LINE 1: 
... INNER JOIN "django_comments" ON ("pi ns_pin"."id" = "django_...
                                                         ^
HINT:  No operator matches the given name and argument type(s). 
You might need to add explicit type casts.
Run Code Online (Sandbox Code Playgroud)

在谷歌搜索之后似乎这个错误在django之前已经被解决了很多次,但我仍然得到它(所有相关问题都在3 - 5年前关闭).我正在使用django 1.4版和最新版本的tastypie.

查询是在orm过滤器下进行的,并且与我的开发数据库(sqlite3)完美配合:

class MyResource(ModelResource):    

    comments = fields.ToManyField('my.api.api.CmntResource', 'comments', full=True, null=True)

    def build_filters(self, filters=None):
        if filters is None:
            filters = {}

        orm_filters = super(MyResource, self).build_filters(filters)

        if 'cmnts' in filters:
            orm_filters['comments__user__id__exact'] = filters['cmnts']

class CmntResource(ModelResource):
    user = fields.ToOneField('my.api.api.UserResource', 'user', full=True) …
Run Code Online (Sandbox Code Playgroud)

django postgresql heroku django-comments tastypie

20
推荐指数
2
解决办法
3万
查看次数

没有运算符匹配给定的名称和参数类型.您可能需要添加显式类型转换. - Netbeans,Postgresql 8.4和Glassfish

我正在尝试使用EclipseLink在Glassfish中使用JPA编辑Postgresql中的表.当我插入一个实体时,它运行正常.但是,当我尝试编辑或删除同一个实体时,它会因以下错误而失败.任何的想法?

Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: operator does not exist: integer = character varying
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 38
Error Code: 0
        at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
        at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.processExceptionForCommError(DatabaseAccessor.java:1422)
        at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:799)
        at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:867)
        at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:587)
        at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:530)
        at org.eclipse.persistence.internal.sessions.AbstractSession.executeCall(AbstractSession.java:914)
        at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:205)
        at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:191)
        at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.deleteObject(DatasourceCallQueryMechanism.java:182)
        at org.eclipse.persistence.internal.queries.StatementQueryMechanism.deleteObject(StatementQueryMechanism.java:101)
        at org.eclipse.persistence.queries.DeleteObjectQuery.executeDatabaseQuery(DeleteObjectQuery.java:167)
        at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:675)
        at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:589)
        at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:109)
        at org.eclipse.persistence.queries.DeleteObjectQuery.executeInUnitOfWorkObjectLevelModifyQuery(DeleteObjectQuery.java:112)
        at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:86) …

java postgresql orm jpa eclipselink

15
推荐指数
4
解决办法
10万
查看次数

Spring 数据存储库将 null 作为 bytea 发送到 PostgreSQL 数据库

从 MySQL 切换到PostgreSQL 后,我发现我的 SQL 查询(spring 数据存储库界面中的 @Query)不再起作用。该问题是由作为bytea发送的值引起的,我收到以下异常:

Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: bigint = bytea
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Run Code Online (Sandbox Code Playgroud)

带有@Query 的存储库:

public interface WineRepository extends PagingAndSortingRepository<Wine, Long> {
    @Query(value = "SELECT * FROM WINE w WHERE (?1 IS NULL OR w.id = ?1)", nativeQuery = true)
    Wine simpleTest(Long id);
}
Run Code Online (Sandbox Code Playgroud)

简单测试:

LOGGER.warn("test1: {}", wineRepository.simpleTest(1L));    //ok
LOGGER.warn("test2: …
Run Code Online (Sandbox Code Playgroud)

java postgresql hibernate spring-data spring-data-jpa

13
推荐指数
2
解决办法
3074
查看次数

将字节转换为二进制字符串

我需要解码一个 base64 字符串并获取一大块二进制文件。

Postgres 中是否有 SQL 函数可以简单地将 abytea转换为二进制字符串表示?
(例如“00010001010101010”。)

postgresql binary-data bytea

6
推荐指数
2
解决办法
8351
查看次数

带有空参数的 Spring Boot 本机查询

我在 Spring Boot 中有一个本机查询,如下所示:

@Query(value = "SELECT t.* FROM Transaction t WHERE " +
    "t.datetime >= TO_TIMESTAMP(?1,'YYYY-MM-ddTHH:MI') " +
    "AND t.datetime < TO_TIMESTAMP(?2,'YYYY-MM-ddTHH:MI') " +
    "AND (t.location_1 = ?3 or ?3 is null) " +
    "LIMIT ?4",
    nativeQuery = true)
    List<Transaction> findBySearchTerms(@Param("fromDateTime") String fromDateTime,
            String toDateTime,
            Integer location1,
            Integer maxCount
            );
Run Code Online (Sandbox Code Playgroud)

对于location1,它可能为空。当我使用 location1 null 运行此查询时,它返回错误消息:org.postgresql.util.PSQLException: ERROR: operator does not exist: bigint = bytea

之后我尝试对参数 3 进行投射:

"AND (?3 is null or t.location_1 = cast(?3 as bigint)) " +
Run Code Online (Sandbox Code Playgroud)

它还会导致错误:org.postgresql.util.PSQLException: ERROR: …

java spring-data-jpa spring-boot

1
推荐指数
1
解决办法
2344
查看次数