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

Postgresql 2D array in database schema generated as 1D array in models.go #1494

Closed
colli173 opened this issue Mar 18, 2022 · 0 comments
Closed

Comments

@colli173
Copy link
Contributor

Version

1.12.0

What happened?

go version: 1.18 (equal results with 1.17.8)

Using TEXT[][] as the column type in postgresql generates a corresponding model with field of type []string, when expected model should contain field of type [][]string. Apologies if this is a known limitation of sqlc.

Relevant log output

No response

Database schema

CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  names text[][]      NOT NULL,
  bio  text
);

SQL queries

No response

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "db",
      "engine": "postgresql",
      "schema": "query.sql",
      "queries": "query.sql",
      "sql_package": "pgx/v4"
    }
  ]
}

Playground URL

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

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@colli173 colli173 added bug Something isn't working triage New issues that hasn't been reviewed labels Mar 18, 2022
@kyleconroy kyleconroy removed the triage New issues that hasn't been reviewed label Aug 29, 2022
kyleconroy pushed a commit that referenced this issue Jul 30, 2023
…#2338)

This PR adds support for generating model fields from multi-dimensional postgresql array columns. The approach here is to pass around an additional column attribute array_bounds representing the dimensions of the postgres array column. When generating code, the array_bounds is checked along is_array to determine the dimensions of the resulting struct field. Would be happy to hear alternative approaches or solutions here as well.

https://www.postgresql.org/docs/14/arrays.html

Fixes issue: #1494
Replaces #1651 #2308 #2309
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