Suppose I have a table foo
in Postgres 11.5:
CREATE TABLE foo (an_int integer, a_varchar varchar(50));
I can select columns unique by integer and grab a couple of the a_varchar
values as samples as follows:
SELECT an_int,
min(a_varchar) min_a_varchar,
max(a_varchar) max_a_varchar
FROM foo
GROUP BY 1;
Suppose I have a table foo2
instead:
CREATE TABLE foo2 (an_int integer, an_hstore hstore);
Is there a similar way to select one row per an_int
and pluck out one or more hstore values? I tried using hstore_to_json()
and it didn't work. Converting to varchar
did work, but I don't know if that preserves data well.
So my best answer so far:
SELECT an_int,
min(an_hstore::varchar) min_an_hstore,
max(an_hstore::varchar) max_an_hstore
FROM foo2
GROUP BY 1;