jet icon indicating copy to clipboard operation
jet copied to clipboard

Add support for postgres TABLESAMPLE

Open Jleagle opened this issue 6 months ago • 2 comments
trafficstars

The is the query i am trying to create:

SELECT project.slug AS "project.slug" FROM public."project" AS project TABLESAMPLE SYSTEM_ROWS(1) LIMIT $1;

Which i can start off with:

stmt := table.Project.SELECT(table.Project.Slug).
		FROM(table.Project).
		LIMIT(1)

But the rest (TABLESAMPLE SYSTEM_ROWS(1)) i can't work out, is it possible?

Thanks.

Jleagle avatar Apr 24 '25 19:04 Jleagle

Unfortunately, customizing table sources is not supported, you'll have to fallback to RawStatements.

go-jet avatar Apr 26 '25 12:04 go-jet

Okay thanks!

Jleagle avatar Apr 26 '25 19:04 Jleagle

Forgot to mention, if your TABLESAMPLE table is part of bigger join, you can avoid making the whole statemnet raw statement, by moving just TABLESAMPLE table into CTE or sub-query.

Check faq.

For instance:

projectTS := CTE("project")
projectTSAllColumns := Project.AllColumns.From(projectTS)

stmt := WITH(
	projectTS.AS(
		RawStatement(`
			select * 
			from project TABLESAMPLE SYSTEM_ROWS(1)
		`),
	),
)(
	SELECT(projectTSAllColumns). 
	FROM(
		projectTS.INNER_JOIN(...),
	),
)

I'll repopen the issue, since TABLESAMPLE is a valid feature request.

go-jet avatar Jul 25 '25 12:07 go-jet