-
Notifications
You must be signed in to change notification settings - Fork 863
Support composite types #2760
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
Comments
Support for composite types of a TABLE/TYPE would be great. A further improvement would be supporting arbitrary record types that don't belong to a TABLE/TYPE if that would be possible. postgres=# select row(1, 'foo');
row
---------
(1,foo)
(1 row) |
Following! Our schema defines tables that use custom types, some of which use additional custom types. My expectation was that Go structs would be generated for these types as they are for tables. Is #309 (comment) still the recommended workaround: create Go structs for custom types by hand then use these in Schema definitions: CREATE TYPE "TransactionMessageHeader" AS (
num_required_signatures SMALLINT,
num_readonly_signed_accounts SMALLINT,
num_readonly_unsigned_accounts SMALLINT
);
CREATE TYPE "TransactionMessage" AS (
header "TransactionMessageHeader",
account_keys BYTEA[],
recent_blockhash BYTEA,
instructions "CompiledInstruction"[]
);
-- other custom types ...
CREATE TABLE transaction (
slot BIGINT NOT NULL,
signature BYTEA NOT NULL,
is_vote BOOL NOT NULL,
message_type SMALLINT, -- 0: legacy, 1: v0 message
legacy_message "TransactionMessage",
v0_loaded_message "LoadedMessageV0",
signatures BYTEA[],
message_hash BYTEA,
meta "TransactionStatusMeta",
write_version BIGINT,
updated_on TIMESTAMP NOT NULL,
index BIGINT NOT NULL,
CONSTRAINT transaction_pk PRIMARY KEY (slot, signature)
); sqlc-generated Go code: type Transaction struct {
Slot int64
Signature []byte
IsVote bool
MessageType pgtype.Int2
LegacyMessage sql.NullString
V0LoadedMessage sql.NullString
Signatures [][]byte
MessageHash []byte
Meta sql.NullString
WriteVersion pgtype.Int8
UpdatedOn pgtype.Timestamp
Index int64
} |
I ran into wanting this because I was using composite types in history tables. See my (now closed) issue #3148 for my motivating example. |
CREATE TYPE
Automatic table types
https://www.postgresql.org/docs/current/rowtypes.html
The text was updated successfully, but these errors were encountered: