i'm trying to extract from a row the fields that are part of the primary index of the table. (as a record)
Example, if I create a table like this:
CREATE TABLE t1 (k1 int not null, k2 int not null, label text, PRIMARY KEY(k1, k2));
INSERT INTO t1(k1,k2,label) values (3,5,'hello');
Then i can do :
SELECT * from json_populate_record(null::t1, '{}');
k1 | k2 | label
----+----+-------
| |
(1 row)
...or i can do...
select row_to_json(row) from (select * from t1) as row;
row_to_json
---------------------------------
{"k1":3,"k2":5,"label":"hello"}
(1 row)
But, i want to do :
SELECT * from json_populate_record(null::t1_pkey, '{}');
k1 | k2 |
----+----+
| |
(1 row)
... or ...
select row_to_json(row::t1_pkey) from (select * from t1) as row;
row_to_json
---------------------------------
{"k1":3,"k2":5}
(1 row)
But, problem:
ERROR: type "t1_pkey" does not exist
This type exists probably somewhere because :
\d t1_pkey
Index "public.t1_pkey"
Column | Type | Definition
--------+---------+------------
k1 | integer | k1
k2 | integer | k2
primary key, btree, for table "public.t1"
Any solution ?