citusdata / citusdata/citus

Wrong column names when using row_to_json on distributed table

Open
#1,485 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C
Stars
12.8k
Forks
794
Avg merge
2d 14h
Merged PRs (30d)
31

Description

When I use `row_to_json` on a distributed table the column names are replaced with `f1`, `f2`, ... Below and example:

```sql
-- Normal table
CREATE TABLE example_normal(
key text PRIMARY KEY,
val text NOT NULL
);

INSERT INTO example_normal (key, val) VALUES ('key1', 'val1');
INSERT INTO example_normal (key, val) VALUES ('key2', 'val2');

-- Distributed table
CREATE TABLE example_dist(
key text PRIMARY KEY,
val text NOT NULL
);

SELECT create_distributed_table('example_dist', 'key');

INSERT INTO example_dist (key, val) VALUES ('key1', 'val1');
INSERT INTO example_dist (key, val) VALUES ('key2', 'val2');
```

When I query the normal table with the following query:

```sql
SELECT row_to_json(tmp)
FROM (SELECT * FROM example_normal) tmp;
```

I get the following correct output:

```
{"key":"key1","val":"val1"}
{"key":"key2","val":"val2"}
```

However, when I query the distributed table with the following query:

```sql
SELECT row_to_json(tmp)
FROM (SELECT * FROM example_dist) tmp;
```

I get the following output with all the column names replaced by `f1`,` f2`, ...:

```
{"f1":"key1","f2":"val1"}
{"f1":"key2","f2":"val2"}
```

How can I query a distributed table and get the correct column names?

System info:
- PostgreSQL: 9.6.3
- Citus: 6.2.2

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.