Open kayshav opened 1 month ago
On further testing, if I add the NOT NULL attribute to the Owner element, then the generated code is correct `CREATE TABLE fleetmanager_schema.tag ( create_date TIMESTAMP DEFAULT NOW() NOT NULL, id int8 NOT NULL, PRIMARY KEY (id),
name VARCHAR(255) NOT NULL, owner fleetmanager_schema.obj_ref NOT NULL, -- This NOT NULL leads to proper code generation devices fleetmanager_schema.obj_ref ARRAY );
type FleetmanagerSchemaTag struct { CreateDate pgtype.Timestamp ID int64 Name string Owner common,ObjRef Devices []common.ObjRef }`
@kayshav I think this behavior is expected, considering that although the nonnull_int8 and nonnull_string types of obj_ref are not null, there is still a possibility that the value of obj_ref is null, for example:
insert into tag(create_date, id, name, owner, devices)
values (now(), 1, 'name', null, null);
The query will not fail, so it is possible to have records with the owner field as null. As the documentation states, if the null parameter in the overrides configuration is set to false, nullable fields will not be overridden.
Version
1.27.0
What happened?
Have a simple ddl for an object in postgres. It uses a TYPE both as an ARRAY and also as a simple object. The sqlc.yaml has an override to map the TYPE (see sqlc.yaml). In the generated code, the ARRAY is mapped correctly to the overridden type but the simple object is mapped to sql.NullString.
Relevant log output
Database schema
SQL queries
Configuration
Playground URL
No response
What operating system are you using?
Linux
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go