Skip to content

Add read-only support for PostgreSQL array columns#3402

Open
bilby91 wants to merge 3 commits intoAzure:mainfrom
crunchloop:feature/postgresql-array-columns-readonly
Open

Add read-only support for PostgreSQL array columns#3402
bilby91 wants to merge 3 commits intoAzure:mainfrom
crunchloop:feature/postgresql-array-columns-readonly

Conversation

@bilby91
Copy link
Copy Markdown

@bilby91 bilby91 commented Mar 30, 2026

Summary

  • Add read-only support for PostgreSQL array columns (int[], text[], boolean[], bigint[], etc.) which previously caused initialization failures
  • Array columns are exposed as GraphQL list types ([Int], [String], etc.) and returned as JSON arrays in REST/MCP responses
  • Array columns are marked read-only and excluded from create/update mutation inputs until write support is implemented

Changes

Core plumbing (database-agnostic):

  • ColumnDefinition: new IsArrayType and ElementSystemType properties
  • SqlMetadataProvider: detect array types (System.Array) during schema introspection
  • SchemaConverter: unwrap array element types and generate ListTypeNode for GraphQL fields
  • EdmModelBuilder: represent array columns as EdmCollectionTypeReference in OData model
  • TypeHelper: fallback handling for unresolved System.Array type

PostgreSQL-specific:

  • PostgreSqlMetadataProvider: override PopulateColumnDefinitionWithHasDefaultAndDbType to resolve element types from information_schema udt_name (_int4int, _textstring, etc.)

Tests:

  • 14 new unit tests (array→ListTypeNode generation, nullability, AutoGenerated directive, byte[] exclusion)
  • 3 new PostgreSQL e2e tests (query by PK, null arrays, multi-row queries)
  • Test schema and config for array_type_table entity

Limitations

  • Read-only: mutations on array columns are blocked (marked as auto-generated/read-only)
  • No OData $filter: filtering on array columns is not supported (no OData array operators)
  • PostgreSQL only: other databases don't have native array types; generic plumbing is in place for future use
  • 1D arrays only: multi-dimensional arrays are not tested/supported

Test plan

  • Unit tests pass (1325/1325, 0 failures)
  • PostgreSQL e2e tests pass (3/3 array tests, 711/711 non-preexisting PG tests)
  • CI pipeline validation (PostgreSQL Docker)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds read-only support for PostgreSQL array columns in DAB so schema introspection and runtime initialization no longer fail when encountering int[], text[], boolean[], bigint[], etc. The change threads array-awareness through metadata, GraphQL schema generation, and the EDM model while keeping arrays excluded from mutation inputs.

Changes:

  • Detect PostgreSQL array columns during metadata introspection, resolve array element CLR types, and mark array columns read-only.
  • Expose array columns as GraphQL list types and represent them as EDM collection properties.
  • Add/extend unit + PostgreSQL e2e test coverage plus schema/config updates for a new array_type_table test entity.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Config/DatabasePrimitives/DatabaseObject.cs Extends ColumnDefinition with IsArrayType/ElementSystemType to carry array metadata.
src/Core/Services/MetadataProviders/SqlMetadataProvider.cs Detects array-typed columns from provider schema and marks them read-only.
src/Core/Services/MetadataProviders/PostgreSqlMetadataProvider.cs Resolves PostgreSQL array element types via information_schema (udt_name) and updates ColumnDefinition.
src/Service.GraphQLBuilder/Sql/SchemaConverter.cs Generates GraphQL fields as ListTypeNode for array columns and adds array-aware system type mapping.
src/Core/Parsers/EdmModelBuilder.cs Emits EDM collection properties for array columns to support OData model building.
src/Core/Services/TypeHelper.cs Adds fallback handling for abstract System.Array in EDM primitive type mapping.
src/Service.Tests/GraphQLBuilder/Sql/SchemaConverterTests.cs Adds unit tests for array→GraphQL list type generation, nullability, directives, and byte[] exclusion.
src/Service.Tests/SqlTests/GraphQLSupportedTypesTests/PostgreSqlGQLArrayTypesTests.cs Adds PostgreSQL e2e GraphQL tests validating array values and null handling.
src/Service.Tests/DatabaseSchema-PostgreSql.sql Adds array_type_table DDL + seed data for PostgreSQL integration tests.
src/Service.Tests/dab-config.PostgreSql.json Adds ArrayType entity configuration (read-only permissions) for PostgreSQL test runs.
src/Service.Tests/UnitTests/SerializationDeserializationTests.cs Updates serialization test expectations to account for added ColumnDefinition fields.

@bilby91 bilby91 force-pushed the feature/postgresql-array-columns-readonly branch from 5bb9456 to 29833c7 Compare March 30, 2026 04:19
@aaronburtle aaronburtle self-assigned this Mar 31, 2026
@aaronburtle
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 6 pipeline(s).

@bilby91
Copy link
Copy Markdown
Author

bilby91 commented Mar 31, 2026

@aaronburtle Thanks for approving CI. I'll take a look at the failing tests and address them.

@bilby91
Copy link
Copy Markdown
Author

bilby91 commented Mar 31, 2026

@aaronburtle I think fixes should be in place.

@aaronburtle
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 6 pipeline(s).

/// PostgreSQL array types in information_schema use udt_name with a leading underscore
/// (e.g., _int4 for int[], _text for text[]).
/// </summary>
private static readonly Dictionary<string, Type> _pgArrayUdtToElementType = new(StringComparer.OrdinalIgnoreCase)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be able to add _json, _jsonb, and _money to this dictionary. Currently these types would work for requests, but will generate the wrong schema types

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense. Will verify they work with some new tests.

@aaronburtle
Copy link
Copy Markdown
Contributor

Looks like we are missing tests on the REST side of things. Should add some simple tests to validate REST works with array types, eg. GET /api/ArrayType and GET /api/ArrayType/id/1

foreach (FieldDefinitionNode field in node.Fields)
{
// Skip array/list type fields (e.g., PostgreSQL array columns) - they cannot be ordered.
if (field.Type.IsListType())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CosmosDB has support for list types, so we can't just broadly skip them here. This needs to be scoped to SQL array columns only without breaking Cosmos list filtering.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is why the CosmosDB pipeline is failing.

@aaronburtle
Copy link
Copy Markdown
Contributor

The PG_SQL Integration test failures are from mismatched configs, need to add the new section to ConfigurationTests.TestReadingRuntimeConfigForPostgreSql.verified.txt

bilby91 and others added 3 commits March 31, 2026 17:49
PostgreSQL array columns (int[], text[], boolean[], bigint[], etc.) were
previously unsupported and caused initialization failures. This change adds
read-only support so array columns are exposed as list types in GraphQL
([Int], [String], etc.) and as JSON arrays in REST responses.

Array columns are marked read-only and excluded from mutation input types
until write support is implemented. The implementation adds generic array
plumbing in the shared SQL layers and PostgreSQL-specific element type
resolution via information_schema udt_name mapping.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add ArrayType entity to postgresql-commands.txt so CI's config generator
includes it, and skip list-type fields in InputTypeBuilder filter/orderby
generation to prevent array columns from being incorrectly processed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add _json, _jsonb, _money to PostgreSQL array type mapping dictionary
- Add json[], jsonb[], money[] columns to array_type_table test schema
- Add REST integration tests for array type endpoints (list, by PK, nulls)
- Update GraphQL array tests to cover new array column types
- Update PostgreSQL snapshot to include ArrayType entity

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bilby91
Copy link
Copy Markdown
Author

bilby91 commented Mar 31, 2026

I handle most of the stuff already. Need to replicate the Cosmos issue locally and get it fixed. Will update when I have that aspect ready.

@bilby91 bilby91 force-pushed the feature/postgresql-array-columns-readonly branch from b9e3435 to 684ced5 Compare March 31, 2026 22:14
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.

3 participants