Giter Site home page Giter Site logo

Comments (2)

inconshreveable avatar inconshreveable commented on May 3, 2024

I just ran into a similar issue. Here's the query which is used to determine whether an insert would put the number of inserted rows matching a condition over a limit:

INSERT INTO foo (bar)
SELECT $1
FROM foo
WHERE tenant_id = $2
HAVING count(*) < $3
RETURNING *;

package query

test.sql:14:17: no column reference found

@nzoschke's workaround works somewhat in that this query works:

INSERT INTO foo (bar)
SELECT $1
FROM foo
WHERE tenant_id = $2
HAVING (count(*)::INTEGER) < $3
RETURNING *;

but it has two problems:

  1. that's unintuitive
  2. (more importantly) the generated column name is Column3 which is both confusing and also will cause the code to break in an unexpected way if the parameter ordinals get changed

from sqlc.

kyleconroy avatar kyleconroy commented on May 3, 2024

@nzoschke thanks for the report. mb_downloaded was being left out because I hadn't added support for mathematical operators. I'm fixing that now.

@inconshreveable your problem appears to be different. I can't reproduce it. Can you open a new issue with a self-contained example? I tried the following SQL but couldn't get it to generate code. It failed with an no column reference found.

CREATE TABLE foo (id text not null);
INSERT INTO foo (id)
    SELECT $1 FROM foo
    HAVING count(*) < $2
RETURNING *;

from sqlc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.