Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query with RANDOM() cannot be generated #3866

Open
erendogan51 opened this issue Mar 1, 2025 · 3 comments
Open

Query with RANDOM() cannot be generated #3866

erendogan51 opened this issue Mar 1, 2025 · 3 comments

Comments

@erendogan51
Copy link

Version

1.28.0

What happened?

Any query i try to generate where a random() function is contained fails to be found and generated. And on a side note, the sqlc playground throws an 500 error response when the version is higher than 1.25.

Relevant log output

# package 
query.sql:3:8: function random(unknown, unknown) does not exist

Database schema

CREATE TABLE foo (
  id   BIGSERIAL PRIMARY KEY,
  value int not null
);

SQL queries

-- name: InsertBarV0 :exec
insert into foo(value)
SELECT random(-100000, -30000);
         
-- name: InsertBarV1 :exec
insert into foo(value)
SELECT random(-100000, -30000)
from generate_series(sqlc.arg('intervalStart')::timestamptz, sqlc.arg('intervalEnd')::timestamptz,
                     sqlc.arg('interval')) g
         cross join generate_series(0, sqlc.arg('multiplier')::int) gg;

Configuration

{
  "version": "2",
  "sql": [{
    "schema": "schema.sql",
    "queries": "query.sql",
    "engine": "postgresql",
    "gen": {
      "go": {
        "out": "db"
      }
    }
  }]
}

Playground URL

https://play.sqlc.dev/p/a2c60ef18b2a8453b0aa6c35c2f9dc6ec903385532362e2bb777d5fd892af60d

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@erendogan51 erendogan51 added the bug Something isn't working label Mar 1, 2025
@jakoguta
Copy link
Contributor

jakoguta commented Mar 3, 2025

The function RANDOM() in PostgreSQL does not take arguments. So the error function random(unknown, unknown) does not exist is valid.

@erendogan51
Copy link
Author

The function RANDOM() in PostgreSQL does not take arguments. So the error function random(unknown, unknown) does not exist is valid.

It was added in Postgres 17.

@jakoguta
Copy link
Contributor

jakoguta commented Mar 3, 2025

This is correct, PostgreSQL 17 has the function random(min, max).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants