Skip to content

fix: handle postgres pgvector table layout - #2748

Open
mtibben wants to merge 2 commits into
quarylabs:mainfrom
mtibben:mtibben/fix-pgvector-formatting
Open

fix: handle postgres pgvector table layout#2748
mtibben wants to merge 2 commits into
quarylabs:mainfrom
mtibben:mtibben/fix-pgvector-formatting

Conversation

@mtibben

@mtibben mtibben commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

PostgreSQL pgvector table formatting should preserve the expected layout for CREATE TABLE statements that combine extension-style vector columns, array types, table constraints, and partition clauses.

The current Postgres formatting path treats pgvector-style vector(...) and adjacent bracketed syntax too broadly, so reflow inserts spaces into PostgreSQL type/reference syntax and removes expected continuation indentation from table constraints. This change gives the parser and reflow config more precise segment types for these constructs so vector(1536), TEXT[], and REFERENCES table(column) keep their PostgreSQL shape while table bodies retain their indentation.

Closes #2747

@mtibben
mtibben marked this pull request as ready for review June 15, 2026 00:52
@mikills

mikills commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Verified locally. The pgvector/Postgres fix looks good, but I think this needs one change before merge.

The new global config:
[sqruff:layout:type:start_square_bracket]
spacing_before = touch:inline

regresses array literals outside Postgres. For example, on this PR:

SELECT [1, 2, 3] AS arr

is fixed to:

SELECT[1, 2, 3] AS arr

for BigQuery, SparkSQL, and DuckDB. On main, those preserve the space.

Could we scope the TEXT[] behavior to the Postgres array datatype suffix instead of changing start_square_bracket
globally? A regression fixture for array literal spacing would be useful too.

The rest looks solid: vector(1536), TEXT[], and REFERENCES table(col) are handled much better.

@mtibben
mtibben force-pushed the mtibben/fix-pgvector-formatting branch 2 times, most recently from e013875 to 7507d8f Compare June 16, 2026 20:24
@mtibben
mtibben force-pushed the mtibben/fix-pgvector-formatting branch from 7507d8f to 00818b8 Compare June 16, 2026 20:25
@mtibben

mtibben commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for catching this. I agreed that the start_square_bracket layout change was too broad, so I removed the global spacing rule and scoped the touch-before behavior to a new Postgres array_type_suffix segment instead.

I also added regression coverage for SELECT [1, 2, 3] AS arr under BigQuery, SparkSQL, and DuckDB, and kept the pgvector/Postgres fixture covering TEXT[], vector(1536), and REFERENCES table(col).

@benfdking

Copy link
Copy Markdown
Collaborator

@mtibben

mtibben commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

This is already partially solved with the correct config as well. Did we consider that?

Looking at your query, though, I think there are still some improvements that we should make. It might be worth just breaking them up a little.

Ah I see - with [sqruff:dialect:postgres] pgvector = true, the pgvector datatype parsing side is already covered, so this PR is bundling that config-dependent behavior with a few separate layout issues.

I’ve split the remaining formatter changes into smaller draft PRs:

I think we can treat this PR as superseded by those smaller PRs and review whichever fixes still make sense independently.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: PostgreSQL CREATE TABLE with pgvector still loses indentation

3 participants