Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    AlexGravenSparkfly
    @AlexGravenSparkfly
    Is there any way to make this work?
    My query is something like this:
    SELECT * FROM items WHERE account_id = $1 AND lower(name) LIKE '%$2%'
    I provide $1 and $2 but it gives me the error
    pq: got 2 parameters but the statement requires 1
    I know if I change that to = $2 it works
    no complaints about "got 2 parameters, requires 1"
    I've tried escaping this multiple ways, but it doesn't work. How are you supposed to use "Like" statements?
    Thanks in advance.
    AlexGravenSparkfly
    @AlexGravenSparkfly
    If I go completely around this and build the string manually, it completely works, but that's VERY prone to SQL injection.
    Samuel Nelson
    @nelsam
    like $2 will work, you just need to add the '%' characters to the string
    also, i really hope you're not actually doing SELECT * in your code
    AlexGravenSparkfly
    @AlexGravenSparkfly
    doesnt
    sorry
    I tried it hence asking here
    (sorry was typing with one hand as was on phone to boss :)
    The query has been slightly changed so as to preserve company IP
    but the point is ONE or the OTHER will work
    where account_id = $1
    OR
    where name like $2 where $2 is "'%" + foo + "%'"
    But I need BOTH to work because I need to do the above query
    How do I do the above query in GORP where it will work?
    That same query done directly to Postgres gives results
    whereas with Gorp it does not
    Samuel Nelson
    @nelsam
    what I said, but you don't use the quotes in $2
    AlexGravenSparkfly
    @AlexGravenSparkfly
    Oh hold on, so where $2 is "%" + foo + "%"
    let me try that
    Samuel Nelson
    @nelsam
    yep, that one should work
    AlexGravenSparkfly
    @AlexGravenSparkfly
    Oh, that's perfect!
    Thanks!
    Let me find the docs and try and add that to them... I'm sure that'll help someone down the road.
    Thanks for your quick and frankly really awesome reply.
    Samuel Nelson
    @nelsam
    no problem :)
    little more technical detail: when postgres does the variable binding, it will figure out the correct type for the value; when it realizes the value is a string, it will effectively add the quotes for you
    so having the quotes around it made postgres bind that as if you were doing like '\'%foo%\''
    Osram-Gru
    @Osram-Gru

    Hi, I'm having problems with the primarykey tag in gorp. It seems to be ignored resep. used as column name !?

    type Meta struct {
        Periodic
        Id        string    `db:"uuid, primarykey"`
        CreatedAt time.Time `db:"createdAt"`
    }

    That ends up in the database as:

     \d gtin
                                 Table "public.gtin"
          Column      |           Type           | Collation | Nullable | Default 
    ------------------+--------------------------+-----------+----------+---------
     uuid, primarykey | text                     |           |          |
    .SetKeys works, but I'd like the tag much more :/
    DB is a postgres.
    Osram-Gru
    @Osram-Gru
    I import gorp "gopkg.in/gorp.v1"
    Osram-Gru
    @Osram-Gru
    ... and it works with v2. Is that mentioned in https://github.com/go-gorp/gorp ?
    Osram-Gru
    @Osram-Gru
    Uh, December 2018 ... seems to be a very active project ;)
    Samuel Nelson
    @nelsam
    ugh, mornings
    alright, so the docs and the readme were updated in master when that feature was added
    which means that if you're looking at the docs or the readme from the v1 version, they won't have that feature
    you have to be looking at master or v2 to see the docs about it
    also, per activity of the project: I merge PRs and I try to keep it caught up with the world, but the other maintainers dropped off the radar and I don't use SQL in my job any more
    so I kind of consider gorp to be a project that is "done" for the most part
    hinet
    @hinet
    I want to ignore a field, but I need to join to query the field. What should I do?
    because this only saves the ID in another table in this table, I need the join query name, so the field representing the ID associated name in the structure is ignored.