Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for json functions #546

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
223 changes: 223 additions & 0 deletions sql/pg_duckdb--0.2.0--0.3.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,226 @@ CREATE AGGREGATE @[email protected]_count_distinct(anyelement)

CREATE DOMAIN pg_catalog.blob AS bytea;
COMMENT ON DOMAIN pg_catalog.blob IS 'The DuckDB BLOB alias for BYTEA';

-- json_exists
CREATE FUNCTION @[email protected]_exists("json" json , path VARCHAR)
RETURNS boolean LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `jsonb_exists(json, VARCHAR)` only works with Duckdb execution.';
END;
$func$;

-- json_extract
CREATE FUNCTION @[email protected]_extract("json" json, path VARCHAR)
RETURNS JSON LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `json_extract(json, VARCHAR)` only works with DuckDB execution.';
END;
$func$;

-- json_extract with path list
CREATE FUNCTION @[email protected]_extract("json" json, path VARCHAR[])
RETURNS JSON LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `json_extract(VARCHAR, VARCHAR)` only works with DuckDB execution.';
END;
$func$;

-- json_extract_string
CREATE FUNCTION @[email protected]_extract_string("json" json, path VARCHAR)
RETURNS VARCHAR LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `json_extract_string(json, VARCHAR)` only works with DuckDB execution.';
END;
$func$;

-- json_extract_string
CREATE FUNCTION @[email protected]_extract_string("json" json, path VARCHAR[])
RETURNS VARCHAR LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `json_extract_string(json, VARCHAR)` only works with DuckDB execution.';
END;
$func$;

-- json_value
CREATE FUNCTION @[email protected]_value("json" json, path VARCHAR)
RETURNS VARCHAR LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `json_value(json, VARCHAR)` only works with DuckDB execution.';
END;
$func$;

-- json_array_length
CREATE FUNCTION @[email protected]_array_length("json" json, path_input VARCHAR)
RETURNS integer LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `json_array_length(json)` only works with DuckDB execution.';
END;
$func$;

-- json_contains
CREATE FUNCTION @[email protected]_contains(json_haystack json, json_needle json)
RETURNS boolean LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `json_contains(json, json)` only works with DuckDB execution.';
END;
$func$;

-- json_keys
CREATE FUNCTION @[email protected]_keys("json" json, path VARCHAR DEFAULT NULL)
RETURNS SETOF VARCHAR LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `json_keys(json, [VARCHAR])` only works with DuckDB execution.';
END;
$func$;

-- json_structure
CREATE FUNCTION @[email protected]_structure("json" json)
RETURNS VARCHAR LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `json_structure(json)` only works with DuckDB execution.';
END;
$func$;

-- json_type
CREATE FUNCTION @[email protected]_type("json" json, path VARCHAR[] DEFAULT NULL)
RETURNS VARCHAR LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `json_type(json)` only works with DuckDB execution.';
END;
$func$;

-- json_valid
CREATE FUNCTION @[email protected]_valid("json" json)
RETURNS boolean LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `json_valid(json)` only works with DuckDB execution.';
END;
$func$;

-- json
CREATE FUNCTION @[email protected]("json" json)
RETURNS VARCHAR LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `json(json)` only works with DuckDB execution.';
END;
$func$;

-- json_group_array
CREATE FUNCTION @[email protected]_group_array(any_element ANYELEMENT)
RETURNS VARCHAR LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `json_group_array(json)` only works with DuckDB execution.';
END;
$func$;

-- json_group_object
CREATE FUNCTION @[email protected]_group_object(key ANYELEMENT, value ANYELEMENT)
RETURNS VARCHAR LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `json_group_object(ANYELEMENT, ANYELEMENT)` only works with DuckDB execution.';
END;
$func$;

-- json_group_structure
CREATE FUNCTION @[email protected]_group_structure("json" json)
RETURNS VARCHAR LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `json_group_structure(json)` only works with DuckDB execution.';
END;
$func$;

-- json_transform
CREATE FUNCTION @[email protected]_transform("json" json, structure VARCHAR)
RETURNS json LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `json_transform(VARCHAR, VARCHAR)` only works with DuckDB execution.';
END;
$func$;

-- from_json
CREATE FUNCTION @[email protected]_json("json" json, structure VARCHAR)
RETURNS VARCHAR LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `from_json(json, VARCHAR)` only works with DuckDB execution.';
END;
$func$;

-- json_transform_strict
CREATE FUNCTION @[email protected]_transform_strict("json" json, structure VARCHAR)
RETURNS VARCHAR LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `json_transform_strict(json, VARCHAR)` only works with DuckDB execution.';
END;
$func$;


-- from_json_strict
CREATE FUNCTION @[email protected]_json_strict("json" json, structure VARCHAR)
RETURNS VARCHAR LANGUAGE 'plpgsql'
SET search_path = pg_catalog, pg_temp
AS
$func$
BEGIN
RAISE EXCEPTION 'Function `from_json_strict(json, VARCHAR)` only works with DuckDB execution.';
END;
$func$;


10 changes: 8 additions & 2 deletions src/pgduckdb_metadata_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,14 @@ BuildDuckdbOnlyFunctions() {
* each of the found functions is actually part of our extension before
* caching its OID as a DuckDB-only function.
*/
const char *function_names[] = {"read_parquet", "read_csv", "iceberg_scan", "iceberg_metadata",
"iceberg_snapshots", "delta_scan", "read_json", "approx_count_distinct"};
const char *function_names[] = {
"read_parquet", "read_csv", "iceberg_scan", "iceberg_metadata",
"iceberg_snapshots", "delta_scan", "read_json", "approx_count_distinct",
"json_exists", "json_extract", "json_extract_string", "json_array_length",
"json_contains", "json_keys", "json_structure", "json_type",
"json_valid", "json", "json_group_array", "json_group_object",
"json_group_structure", "json_transform", "from_json", "json_transform_strict",
"from_json_strict", "json_value"};

for (uint32_t i = 0; i < lengthof(function_names); i++) {
CatCList *catlist = SearchSysCacheList1(PROCNAMEARGSNSP, CStringGetDatum(function_names[i]));
Expand Down
Loading
Loading