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

RECURSIVE cte failed with star expansion failed for query #3286

Open
anthonycj04 opened this issue Mar 21, 2024 · 1 comment
Open

RECURSIVE cte failed with star expansion failed for query #3286

anthonycj04 opened this issue Mar 21, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@anthonycj04
Copy link

Version

1.25.0

What happened?

Failed to generate go model when using recursive CTE

Relevant log output

-- With database-backed analysis
# package
db/queries/tickers.sql:1:1: star expansion failed for query

-- Without database-backed analysis
# package
db/queries/tickers.sql:1:1: edit start location is out of bounds

Database schema

CREATE TYPE ticker_symbol AS enum('btc', 'eth', 'usdt');
CREATE TABLE tickers(
	symbol ticker_symbol NOT NULL,
	timestamp bigint NOT NULL,
	ask numeric NOT NULL,
	bid numeric NOT NULL,
	price numeric NOT NULL,
	source text NOT NULL,
	is_processed boolean NOT NULL DEFAULT FALSE,
	created_at timestamp NOT NULL DEFAULT NOW(),
	updated_at timestamp NOT NULL DEFAULT NOW(),
	PRIMARY KEY (symbol, timestamp)
);

SQL queries

-- name: GetLatestTickers :many
WITH RECURSIVE cte AS (
	(
		SELECT *
		FROM tickers
		ORDER BY symbol,
			timestamp DESC
		LIMIT 1
	)
	UNION ALL
	SELECT l.*
	FROM cte c
		CROSS JOIN LATERAL (
			SELECT *
			FROM tickers t
			WHERE t.symbol > c.symbol
			ORDER BY t.symbol,
				t.timestamp DESC
			LIMIT 1
		) l
) TABLE cte
ORDER BY symbol;

Configuration

version: "2"
sql:
- schema: "schema.sql"
  queries: "query.sql"
  engine: "postgresql"
  database:
    uri: xxx
  gen:
    go:
      out: db
      sql_package: "pgx/v5"

Playground URL

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

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@anthonycj04 anthonycj04 added bug Something isn't working triage New issues that hasn't been reviewed labels Mar 21, 2024
@semanser
Copy link

The same error happens if sqlc can't find your schema. Make sure that schema field in sqlc.yml points to a correct location.

@kyleconroy kyleconroy removed the triage New issues that hasn't been reviewed label Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants