Skip to content

Commit 2b10f5f

Browse files
committed
docs: list the PostgreSQL type spellings sqlcj accepts
1 parent f5512c0 commit 2b10f5f

1 file changed

Lines changed: 22 additions & 24 deletions

File tree

‎docs/postgresql.md‎

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,16 @@ accepted and map exactly like their unparameterized spellings.
110110

111111
| Accepted SQL spellings | Java type | Notes |
112112
| --- | --- | --- |
113-
| `INTEGER`, `INT`, `SERIAL` | `Integer` | A `SERIAL` column is always modeled non-null. |
114-
| `BIGINT`, `BIGSERIAL` | `Long` | A `BIGSERIAL` column is always modeled non-null. |
115-
| `SMALLINT` | `Short` | |
113+
| `INTEGER`, `INT`, `INT4`, `SERIAL`, `SERIAL4` | `Integer` | A serial column is always modeled non-null. |
114+
| `BIGINT`, `INT8`, `BIGSERIAL`, `SERIAL8` | `Long` | A serial column is always modeled non-null. |
115+
| `SMALLINT`, `INT2`, `SMALLSERIAL`, `SERIAL2` | `Short` | A serial column is always modeled non-null. |
116116
| `BOOLEAN`, `BOOL` | `Boolean` | |
117-
| `VARCHAR` | `String` | |
117+
| `VARCHAR`, `CHARACTER VARYING` | `String` | |
118+
| `CHAR`, `CHARACTER` | `String` | PostgreSQL blank-pads a stored value to the declared length, so `ab` written into a `CHAR(3)` column reads back as `ab `. |
118119
| `TEXT` | `String` | |
119120
| `DATE` | `java.time.LocalDate` | |
120-
| `TIMESTAMP` | `java.time.LocalDateTime` | |
121-
| `TIMESTAMP WITH TIME ZONE` | `java.time.OffsetDateTime` | PostgreSQL normalizes the stored value to the session time zone, so a value read back equals the written value by instant rather than by offset. |
121+
| `TIMESTAMP`, `TIMESTAMP WITHOUT TIME ZONE` | `java.time.LocalDateTime` | |
122+
| `TIMESTAMP WITH TIME ZONE`, `TIMESTAMPTZ` | `java.time.OffsetDateTime` | PostgreSQL normalizes the stored value to the session time zone, so a value read back equals the written value by instant rather than by offset. |
122123
| `DECIMAL`, `NUMERIC` | `java.math.BigDecimal` | |
123124
| `UUID` | `java.util.UUID` | |
124125

@@ -185,9 +186,10 @@ Nullability itself is parsed from `NOT NULL` only:
185186

186187
- a column without `NOT NULL` is modeled nullable, so a column declared bare
187188
`PRIMARY KEY` is modeled nullable,
188-
- a `SERIAL` or `BIGSERIAL` column is always modeled non-null, because
189-
PostgreSQL defines those spellings as an integer type with a sequence default
190-
and `NOT NULL`,
189+
- a serial column, declared `SMALLSERIAL`, `SERIAL`, `BIGSERIAL`, `SERIAL2`,
190+
`SERIAL4`, or `SERIAL8`, is always modeled non-null, because PostgreSQL
191+
defines those spellings as an integer type with a sequence default and
192+
`NOT NULL`,
191193
- nullability never changes a generated Java type. It is carried into the
192194
analyzed model, but the generated type is resolved from the column type alone.
193195

@@ -198,14 +200,6 @@ columns of the integration schema snapshot, which cover `SMALLINT`, `VARCHAR`,
198200

199201
## Unsupported Types and DDL
200202

201-
These spellings are rejected even though PostgreSQL accepts them:
202-
203-
- `TIMESTAMPTZ`
204-
- `SERIAL4`
205-
- `SERIAL8`
206-
- `SMALLSERIAL`
207-
- `TIMESTAMP WITHOUT TIME ZONE`
208-
209203
The following type families are not supported at all, because only the
210204
spellings listed in [Supported Column Types](#supported-column-types) are
211205
accepted:
@@ -235,7 +229,7 @@ The message names the schema source and the offending type or statement, or the
235229
syntax error with the line and column it was found at:
236230

237231
```text
238-
sqlcj: Invalid schema source /home/dev/project/schema.sql: Unsupported SQL column type: TIMESTAMPTZ
232+
sqlcj: Invalid schema source /home/dev/project/schema.sql: Unsupported SQL column type: JSONB
239233
sqlcj: Invalid schema source /home/dev/project/schema.sql: Unsupported schema statement: Alter
240234
sqlcj: Invalid schema source /home/dev/project/schema.sql: Encountered unexpected token: ";" <ST_SEMICOLON> at line 4, column 1
241235
```
@@ -244,13 +238,16 @@ sqlcj: Invalid schema source /home/dev/project/schema.sql: Encountered unexpecte
244238

245239
Type table:
246240

247-
- `DefaultSchemaParserTest.shouldKeepParsingDeliveredColumnTypes` and
248-
`DefaultSchemaParserTest.shouldParseAddedColumnTypes` cover the accepted
241+
- `DefaultSchemaParserTest.shouldKeepParsingDeliveredColumnTypes`,
242+
`DefaultSchemaParserTest.shouldParseAddedColumnTypes`, and
243+
`DefaultSchemaParserTest.shouldParsePostgresTypeSpellings` cover the accepted
249244
spellings, their case-insensitive forms, and the ignored type arguments.
250245
- `PostgresIntegrationTest.shouldExecuteGeneratedOneQueryAgainstPostgres`,
251-
`PostgresIntegrationTest.shouldExecuteGeneratedWriteAgainstPostgres`, and
252-
`PostgresIntegrationTest.shouldRoundTripSerialUuidAndTimestampWithTimeZoneValues`
253-
execute the Java mappings against PostgreSQL 16.
246+
`PostgresIntegrationTest.shouldExecuteGeneratedWriteAgainstPostgres`,
247+
`PostgresIntegrationTest.shouldRoundTripSerialUuidAndTimestampWithTimeZoneValues`,
248+
and `PostgresIntegrationTest.shouldRoundTripPostgresTypeSpellingValues`
249+
execute the Java mappings, including the blank-padded `CHAR` values, against
250+
PostgreSQL 16.
254251
- `DefaultSchemaParserTest.shouldRejectUnsupportedColumnType` covers the
255252
rejected spellings.
256253

@@ -278,7 +275,8 @@ Nulls:
278275
proves that row absence is reported by `:optional` and `:one` rather than by a
279276
null result.
280277
- `DefaultSchemaParserTest.shouldParseColumns`,
281-
`DefaultSchemaParserTest.shouldParseNullabilityOfAddedColumnTypes`, and
278+
`DefaultSchemaParserTest.shouldParseNullabilityOfAddedColumnTypes`,
279+
`DefaultSchemaParserTest.shouldParseNullabilityOfIntegerAliasColumns`, and
282280
`DefaultSchemaParserTest.shouldParseSerialColumnAsNotNullable` cover parsed
283281
nullability.
284282

0 commit comments

Comments
 (0)