Skip to content

Instantly share code, notes, and snippets.

View rafaelveloso's full-sized avatar
🎯
Focusing

Rafael Veloso rafaelveloso

🎯
Focusing
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Keybase proof

I hereby claim:

  • I am rafaelveloso on github.
  • I am rafaelveloso (https://keybase.io/rafaelveloso) on keybase.
  • I have a public key whose fingerprint is C2DC 4D2E 8940 9AA3 E2B3 E598 F336 4816 A3AC 8AC1

To claim this, I am signing this object:

@rafaelveloso
rafaelveloso / jsonb_equality_operator.sql
Created June 11, 2015 10:30
JSONB Equality Operator
CREATE OR REPLACE FUNCTION jsonb_equality(left_arg jsonb, right_arg jsonb)
RETURNS bool AS
$BODY$
SELECT left_arg @> right_arg AND left_arg <@ right_arg;
$BODY$
LANGUAGE SQL IMMUTABLE STRICT;
CREATE OPERATOR = (
LEFTARG = jsonb,
RIGHTARG = jsonb,
CREATE OR REPLACE FUNCTION json_access(obj json, path text) RETURNS json AS $$
var obj = JSON.parse(obj);
var paths = path.split(".");
var p;
var ret;
while (p = paths.shift()) {
if (typeof obj[p] == 'undefined'){
obj = null;
break
}
@rafaelveloso
rafaelveloso / to_json.sql
Last active August 29, 2015 14:13 — forked from wolph/to_json.sql
CREATE OR REPLACE FUNCTION escape_json (text) RETURNS text AS $$
SELECT replace($1, '''', '\'''); $$ LANGUAGE SQL IMMUTABLE;
CREATE OR REPLACE FUNCTION to_json(text) RETURNS text AS $$
SELECT escape_json($1) $$ LANGUAGE SQL IMMUTABLE;
CREATE OR REPLACE FUNCTION to_json(KEY text, value text) RETURNS text AS $$
SELECT '''' || to_json($1) || ''': ''' || to_json($2) || ''''; $$ LANGUAGE SQL IMMUTABLE;
@rafaelveloso
rafaelveloso / plv8-javascript-modules-loading.sql
Last active December 6, 2019 14:21
How to load Javascript modules into postgres using plv8
/******************************************************************************
How to load Javascript modules into postgres
******************************************************************************/
CREATE EXTENSION IF NOT EXISTS plv8
/******************************************************************************
First step is download the Javascript module file
Example with undescore-min and node-jpath
******************************************************************************/