You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Array serialization does not work with custom array types #592
They probably still have to make their own parser/serialiser for it.
I might be misunderstanding, but this feels like an example where a custom parser/serializer shouldn't be necessary. In the example, my_custom_array_type is effectively an alias of text[], so it should already work with the built-in serializers.
Perhaps there's something about the query in fetchArrayTypes that isn't making that association work?
t('Insert array into custom domain array',async()=>{awaitsql`create domain my_custom_array_type as text[]`awaitsql`create table test (x my_custom_array_type)`awaitsql`insert into test ${sql({x: [['a']]})}`})
I guess it would be possible, but not sure how it should be implemented.
You can fetch the base type this way (there is probs an easier query I just edited the current one):
SELECT
DISTINCT ON (b.oid) b.oid,
b.typarray,
CASE
WHEN b.typbasetype>0
THEN c.oid
ELSE NULL
END AS baseoid,
CASE
WHEN b.typbasetype>0
THEN c.typarray
ELSE NULL
END AS basetyparray
FROMpg_catalog.pg_type a
LEFT JOINpg_catalog.pg_type b ONb.oid=a.typelemJOINpg_catalog.pg_type c
ONc.typarray=b.typbasetypeORc.oid=b.typbasetypeWHEREa.typcategory='A'GROUP BYb.oid,
b.typarray,
c.oid,
c.typarrayORDER BYb.oid
This query might help in case somebody wants to write a custom type serializer/parser:
WITH cols AS (
SELECTpg_catalog.format_type(t.oid,null) tuple,
t.oidasoid,
t.typarrayas array_oid,
a.attname column_name,
a.attnum column_num,
a.atttypidas column_oid
FROMpg_catalog.pg_attribute a
JOINpg_catalog.pg_type t ON (a.attrelid=t.typrelid)
JOINpg_catalog.pg_namespace n ON (n.oid=t.typnamespace)
WHEREn.nspname= current_schema() ANDa.attnum>0AND NOT a.attisdropped
)
SELECTcols.tuple,
cols.oid,
cols.array_oid,
array_agg(cols.column_nameORDER BYcols.column_numASC) column_names,
array_agg(cols.column_oidORDER BYcols.column_numASC) column_oids
FROM cols
GROUP BY1, 2, 3;
Activity
porsager commentedon Apr 27, 2023
Just merged a PR that should fix this #578
Can you check how that works?
Bas950 commentedon Apr 27, 2023
They probably still have to make their own parser/serialiser for it.
sds commentedon Apr 27, 2023
I still receive the same error with that change.
I might be misunderstanding, but this feels like an example where a custom parser/serializer shouldn't be necessary. In the example,
my_custom_array_typeis effectively an alias oftext[], so it should already work with the built-in serializers.Perhaps there's something about the query in
fetchArrayTypesthat isn't making that association work?sds commentedon Apr 27, 2023
Here's a test that reproduces the failure:
Bas950 commentedon May 2, 2023
I guess it would be possible, but not sure how it should be implemented.
You can fetch the base type this way (there is probs an easier query I just edited the current one):
@porsager any ideas?
marcbachmann commentedon May 7, 2023
This query might help in case somebody wants to write a custom type serializer/parser:
v4