How to create the array of rows by hand in PostgreSQL?
Asked Answered
I

1

0

I'm trying to create the array of rows with ::RECORD[] or ::RECORD by hand as shown below:

SELECT ARRAY['(John,Smith)','(David,Miller)']::RECORD[];

Or:

SELECT ARRAY['(John,Smith)'::RECORD,'(David,Miller)'::RECORD];

But I got the error below:

ERROR: input of anonymous composite types is not implemented

Actually, I could run the query without ::RECORD[] or ::RECORD below but the type is TEXT[]:

SELECT ARRAY['(John,Smith)','(David,Miller)'];

So, how can I create the array of rows by hand?

Inorganic answered 7/2 at 6:26 Comment(0)
A
3

The answer is kind of already in your question: you could use row() constructors. Demo:

select array[row('a',1,true),row('b',4,false)];
array
{"(a,1,t)","(b,4,f)"}
select pg_typeof(array[row('a',1,true),row('b',4,false)]);
pg_typeof
record[]
Aube answered 7/2 at 6:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.