Hello crdb friends,
I’m looking for a reference docs on built-in functions supported by crdb. I read the following pages, but could not find more detailed documentation:
- https://www.cockroachlabs.com/blog/json-coming-to-cockroach/
- https://github.com/cockroachdb/cockroach/pull/20214
- https://www.cockroachlabs.com/docs/v2.1/functions-and-operators.html
From the last page, I found the function I needed json_object_keys(input: jsonb) → string
for my query:
Upon query execution, I received an error message:
Query 1:
root@:26257/test_crdb> select json_object_keys(data->'perflogs') as data from "ProcessLogs" limit 1;
pq: column name "data" not found
root@:26257/test_crdb> show create table "ProcessLogs";
+---------------+--------------------------------------------------------------------------+
| Table | CreateTable |
+---------------+--------------------------------------------------------------------------+
| "ProcessLogs" | CREATE TABLE "ProcessLogs" ( |
| | |
| | key STRING(128) NOT NULL, |
| | |
| | data JSON NOT NULL, |
| | |
| | iso_timestamp TIMESTAMP WITH TIME ZONE NOT NULL, |
| | |
| | unix_timestamp INT NOT NULL, |
| | |
| | source STRING NOT NULL, |
| | |
| | CONSTRAINT "primary" PRIMARY KEY (key ASC), |
| | |
| | INDEX "ProcessLogs_source_unix_timestamp_idx" (source ASC, |
| | unix_timestamp ASC), |
| | |
| | FAMILY "primary" (key, data, iso_timestamp, unix_timestamp, source) |
| | |
| | ) |
+---------------+--------------------------------------------------------------------------+
(1 row)
And if I were to run a simpler select
query, it would run just fine…
root@:26257/test_crdb> select data->'perflogs' as data from "ProcessLogs" limit 1;
+--------------------------------------------------------------------------+
| data |
+--------------------------------------------------------------------------+
| {"07e9e530-ea12-11e8-b170-51f9d11d2758": {"crumb": |
... /*result abridged*/
The same query statement executes successfully in RDS PostgreSQL
my_dev_db=> select jsonb_object_keys(data->'perflogs') as data from "ProcessLogs" limit 1;
data
--------------------------------------
c35b2a0e-ede7-11e8-b5a2-c93693164324
(1 row)
my_dev_db=> \d "ProcessLogs";
Table "public.ProcessLogs"
Column | Type | Collation | Nullable | Default
----------------+--------------------------+-----------+----------+---------
key | character varying(128) | | not null |
data | jsonb | | not null |
iso_timestamp | timestamp with time zone | | not null |
unix_timestamp | bigint | | not null |
source | text | | not null |
Indexes:
"ProcessLogs_pkey" PRIMARY KEY, btree (key)
"ProcessLogs_source_unix_timestamp_idx" btree (source, unix_timestamp)
I know in the crdb case I use json
data type instead of jsonb
(even though i specified it as jsonb
in the create table
DDL, but perhaps that’s a separate topic) as in the case of pg, but when I replaced it to using jsonb_object_keys
function it still failed. Am I missing something in the crdb case?
Thanks in advance for the help.