construcción predeterminada (por defecto, en PLV8 v3.0.0 y versiones superiores, los números BigInt se convierten en cadenas)
CREATE TABLE test
(
id SERIAL PRIMARY KEY NOT NULL,
comment text
);
INSERT INTO test(comment)
VALUES ('abc'), ('def');
CREATE OR REPLACE FUNCTION get_count(table_name text)
RETURNS jsonb
LANGUAGE plv8 IMMUTABLE AS
$$
const sql = `SELECT COUNT(*) AS cnt FROM "${table_name}"`;
const data = plv8.execute(sql);
return data[0];
$$;
SELECT * FROM get_count('test');
CREATE TABLE test
(
id SERIAL PRIMARY KEY NOT NULL,
comment text
);
INSERT INTO test(comment)
VALUES ('abc'), ('def');
CREATE OR REPLACE FUNCTION get_count(table_name text)
RETURNS jsonb
LANGUAGE plv8 IMMUTABLE AS
$$
const sql = `SELECT COUNT(*) AS cnt FROM "${table_name}"`;
const data = plv8.execute(sql);
return data[0];
$$;
SELECT * FROM get_count('test');