-
-
Notifications
You must be signed in to change notification settings - Fork 30
Add ROW()
record constructor support
#1451
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
base: main
Are you sure you want to change the base?
Conversation
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't the right direction to head in. There isn't a tuple
type in Postgres.
SELECT * FROM pg_type ORDER BY typname;
The ROW()
expression works with composite and anonymous RECORD
types, as described in the documentation here:
https://www.postgresql.org/docs/15/sql-expressions.html#SQL-SYNTAX-ROW-CONSTRUCTORS
With types, we are adhering to Postgres' documentation as close as possible. All of the functions for each type (bpcharin
, timestamp_recv
, etc.) are functions that exist within Postgres, and for those you can find them in pg_type
. The comparison functions (int4gt
, etc.) exist in the pg_operator
table:
SELECT
o.oprname,
src_typ.typname AS oprleft,
tgt_typ.typname AS oprright,
res_typ.typname AS oprresult,
o.oprcode::varchar
FROM
pg_operator o
JOIN
pg_catalog.pg_type src_typ ON o.oprleft = src_typ.oid
JOIN
pg_catalog.pg_type tgt_typ ON o.oprright = tgt_typ.oid
JOIN
pg_catalog.pg_type res_typ ON o.oprresult = res_typ.oid
WHERE
o.oprname = '>'
ORDER BY
src_typ.typname, tgt_typ.typname;
The best way to proceed would be to add support for composite types, and then follow that up with RECORD
types (which you may remember seeing a taste of it in my triggers PR, which added enough of RECORD
to work with the OLD
and NEW
values in trigger functions).
I've thought about how to properly implement RECORD
types for a little bit (mainly while implementing triggers), and one potential idea for anonymous record types would be to have the row and types combined into a single value. So it would look something like:
type RecordValue struct {
Value sql.Row
Types []id.Type
}
This works on the assumption that an array of anonymous RECORD
values could each have a different row representation, but that may not be true (would need to follow that up with a bit of reading).
3a9f55b
to
18f5ccd
Compare
ROW()
supportROW()
record constructor support
@Hydrocharged – |
This is definitely a step in the right direction, but there are some details that we need to nail down before we can merge this in. For example, right now comparisons are done by directly comparing the values. My hunch would be that they use the comparison functions for the appropriate types, which would need the type information available at that point. When you're back next week, we can hop on a quick call and go over a few more details. |
Initial support for the
ROW()
constructor expression, which creates anonymous records.This PR adds support for basic uses of the
ROW()
constructor, such as creating records from groups of expressions, selecting records, comparing records, and using records inWHERE
clauses. There are still severalrecord
features that don't work yet, such as using a table alias with theROW()
constructor.Fixes: #1425