[2.0.1-Scala]: ERROR: column "id" is of type bigint but expression is of type character varying [error] Hint: You will need to rewrite or cast the expression.

12,290 views
Skip to first unread message

tmueller

unread,
Jun 13, 2012, 2:36:51 PM6/13/12
to play-fr...@googlegroups.com
Hey everyone,

I am stuck on this error that I cant seem to get past.

ERROR: column "id" is of type bigint but expression is of type character varying [error]   Hint: You will need to rewrite or cast the expression.

Here is my evolution:

CREATE SEQUENCE account_id_seq;


CREATE TABLE account (

id integer NOT NULL PRIMARY KEY DEFAULT nextval('account_id_seq'),

    email      text NOT NULL,

    password   text NOT NULL,

    name       text NOT NULL

);

ALTER SEQUENCE account_id_seq OWNED BY account.id;

Here is my test that fails.

  "The user class" should {

    

  "be persisted" in {

  implicit val context = inMemoryContext 

  running(FakeApplication()) {

  User.create(User("emailaddress", "password", "Name"))

  User.findAll must have size 1

  }

  }

  }


and User.scala code:


/**

   * Create a User.

   */

  def create(user: User): User = {

    DB.withConnection { implicit connection =>

      SQL(

        """

          insert into account values (

          {email}, {password}, {name}

          )

        """

      ).on(

        'email -> user.email,

        'password -> user.password,

        'name -> user.name

      ).executeUpdate()

        val id = SQL("SELECT SCOPE_IDENTITY()")().collect {

          case Row(id: Int) => id

        }.head

        return User(user.email, user.password, user.name, new Id(id))

user

    }

  }


Im stumped as to why I am getting this error. Any ideas why I get this?


Todd












tmueller

unread,
Jun 13, 2012, 2:51:05 PM6/13/12
to play-fr...@googlegroups.com
The database is PostgreSQL 9.1


Todd

johanandren

unread,
Jun 13, 2012, 3:48:03 PM6/13/12
to play-fr...@googlegroups.com
Since you do not define which columns to insert into, the query 

   insert into account values (

          {email}, {password}, {name}

          )


Means insert email into the first column, which is id.

What you want to do is to specify what columns to insert the values into:
insert into account (email, password, name) values ({email}, {password}, {name}) 

tmueller

unread,
Jun 13, 2012, 4:20:28 PM6/13/12
to play-fr...@googlegroups.com
Sigghhh.

Thank you for catching that. I had been focusing on the evolutions and db structure than the actual insert statement.

Is there a way to capture or record what the raw sql is when a query is run?


Thank you!
Reply all
Reply to author
Forward
0 new messages