Re: [scalikejdbc-users-group:717] Failed to retrieve value because Column 'count' not found

147 views
Skip to first unread message

Kazuhiro Sera

unread,
Mar 17, 2020, 9:10:46 PM3/17/20
to Alvin Alexander, ScalikeJDBC Users Group
Hello Alvin,

Thank you for asking a question here!

It looks like an issue inside your method - WhatsRelatedLink.fromDb. Probably you're specifying the name `count` for data extraction from ResultSet. However, according to the code you shared with us, it seems to be COUNT_TN_NID as you named so.

Best,
Kaz


On Wed, Mar 18, 2020 at 9:40 AM Alvin Alexander <a...@alvinalexander.com> wrote:
Hello,

I’m trying to use this function:

def getWhatsRelatedLinks(nid: Int): Seq[WhatsRelatedLink] = DB.readOnly { implicit session =>
    sql"""
    select tn.nid, count(tn.nid) as COUNT_TN_NID, u.alias, n.title
    from taxonomy_index tn, url_alias u, node_field_data n
    where tn.tid in (select tid from taxonomy_index where nid = $nid)
    and tn.nid = u.nid
    and tn.nid = n.nid
    and n.status = 1
    and n.nid != $nid
    group by tn.nid
    order by COUNT_TN_NID desc
    limit 5
    """
        .map(WhatsRelatedLink.fromDb)
        .list()
        .apply()
}


The SQL in that function works fine when I run it through the MySQL command line with a sample nid value, but I get this error when calling that function:

[error] (run-main-8) scalikejdbc.ResultSetExtractorException: Failed to retrieve value because Column 'count' not found.. If you're using SQLInterpolation, you may mistake u.id for u.resultName.id.
[error] scalikejdbc.ResultSetExtractorException: Failed to retrieve value because Column 'count' not found.. If you're using SQLInterpolation, you may mistake u.id for u.resultName.id.
[error]     at scalikejdbc.WrappedResultSet.wrapIfError(WrappedResultSet.scala:35)


For some reason it can’t run the count function. I’m using ScalikeJDBC 3.1.0, mysql-connector-java 8.0.19, and a MySQL 5.6.35 database with Scala 2.12.8.

Any help is appreciated.

Thanks,
Al





--
You received this message because you are subscribed to the Google Groups "ScalikeJDBC Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalikejdbc-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalikejdbc-users-group/4aaf328f-cabb-4393-8a11-d2c0e9a97fe5%40googlegroups.com.

Alvin Alexander

unread,
Mar 17, 2020, 9:22:56 PM3/17/20
to ScalikeJDBC Users Group
Hi Kaz,

Thank you. Yes, I realized my error shortly after posting this. I initially had this code:

count(tn.nid) as COUNT_TN_NID

written like this:

count(tn.nid)

I just added the “as” part shortly before posting this, and then that variable name I used eventually made me realize that I had a very different variable name in my WrappedResultSet code. I tried to delete this message after I realized what I had done wrong, but it looks like it was not deleted.

Thanks for your reply, I appreciate it!

All the best,
Al
To unsubscribe from this group and stop receiving emails from it, send an email to scalikejdbc-users-group+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages