Type error for Postgres 'serial' types

24 views
Skip to first unread message

edoloughlin

unread,
Oct 4, 2010, 6:28:35 AM10/4/10
to clj-record-dev
I'm using the Postgres 'serial' type for a primary key:

CREATE TABLE "users" ("id" serial primary key);

When I call '(get-record id)' on my model, I get an exception warning
about an invalid type.

I'm using Postgres 8.4.4 with postgresql-9.0-801.jdbc4.jar.

Is there a way of telling clj-record that the primary key isn't a
'character varying'?

Here's the stack trace:

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: 30
at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:
2102)
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:
1835)
at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:
257)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:
500)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:
388)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:
273)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:90)
at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:
265)
at clojure.contrib.sql.internal
$with_query_results_STAR_.invoke(internal.clj:193)
at clj_record.core$find_by_sql
$func__1606__auto____1618.invoke(core.clj:66)
at clj_record.core$find_by_sql$fn__1624.invoke(core.clj:65)
at clojure.contrib.sql.internal
$with_connection_STAR_.invoke(internal.clj:105)
at clj_record.core$find_by_sql.invoke(core.clj:65)
at clj_record.core$find_records.invoke(core.clj:79)
at clj_record.core$find_record.invoke(core.clj:85)
at clj_record.core$get_record.invoke(core.clj:90)
at neataudio.domain.user$get_record.invoke(user.clj:17)
at neataudio.domain.user$get.invoke(user.clj:50)
at neataudio.web$fn__1826$fn__1827.invoke(web.clj:35)
at compojure.core$routes$fn__748$fn__749.invoke(core.clj:71)
at clojure.core$some.invoke(core.clj:2053)
at compojure.core$routes$fn__748.invoke(core.clj:71)
at ring.middleware.params$wrap_params$fn__389.invoke(params.clj:76)
at ring.middleware.cookies$wrap_cookies$fn__589.invoke(cookies.clj:
124)
at ring.middleware.json_params$wrap_json_params
$fn__1184.invoke(json_params.clj:19)
at neataudio.web$wrap_error_handling$fn__1812.invoke(web.clj:21)
at clojure.lang.Var.invoke(Var.java:365)
at ring.adapter.jetty$proxy_handler$fn__304.invoke(jetty.clj:17)
at ring.adapter.jetty.proxy$org.mortbay.jetty.handler.AbstractHandler
$0.handle(Unknown Source)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
534)
at org.mortbay.jetty.HttpConnection
$RequestHandler.headerComplete(HttpConnection.java:864)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:533)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:207)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:403)
at org.mortbay.jetty.bio.SocketConnector
$Connection.run(SocketConnector.java:228)
at org.mortbay.thread.QueuedThreadPool
$PoolThread.run(QueuedThreadPool.java:522)

John D. Hume

unread,
Oct 4, 2010, 3:21:30 PM10/4/10
to clj-rec...@googlegroups.com
Hi there,
I'm afraid I haven't tested with Postgresql, but I know others have,
though I can't guarantee it's been recently.

I notice from the backtrace that this is in a web app. I'm guessing
when you call '(get-record id)' that id is a String pulled from
params. If so, can you try converting it with something like
'(get-record (Integer/parseInt id))'?

Assuming that is the issue, should get-record be modified to accept a
String argument and do this conversion? How are others handling this
already?

Thanks.
-hume.

On Mon, Oct 4, 2010 at 6:28 AM, edoloughlin <ed.olo...@gmail.com> wrote:
> I'm using the Postgres 'serial' type for a primary key:
>
>  CREATE TABLE "users" ("id" serial primary key);
>
> When I call '(get-record id)' on my model, I get an exception warning
> about an invalid type.
>
> I'm using Postgres 8.4.4 with postgresql-9.0-801.jdbc4.jar.
>
> Is there a way of telling clj-record that the primary key isn't a
> 'character varying'?
>
> Here's the stack trace:
>
> 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.

...

Reply all
Reply to author
Forward
0 new messages