{"id":43583,"library":"pg-sql-helpers","title":"pg-sql-helpers","description":"A dynamic SQL query helper library (v0.3.7) built on top of pg-sql, providing a lodash-like toolkit for constructing INSERT, UPDATE, WHERE, ORDER BY, and other SQL clauses programmatically without string concatenation. Released by Ian Storm Taylor, with low release cadence (last update 2016). Key differentiator: allows SQL-native template syntax via pg-sql while adding helpers for dynamic clauses, unlike ORMs or full query builders.","status":"active","version":"0.3.7","language":"javascript","source_language":"en","source_url":"git://github.com/ianstormtaylor/pg-sql-helpers","tags":["javascript","dynamic","escape","interpolate","orm","pg","pg-sql","pgsql","postgres"],"install":[{"cmd":"npm install pg-sql-helpers","lang":"bash","label":"npm"},{"cmd":"yarn add pg-sql-helpers","lang":"bash","label":"yarn"},{"cmd":"pnpm add pg-sql-helpers","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; required for sql template tag and value escaping","package":"pg-sql","optional":false}],"imports":[{"note":"Named export; cannot be default imported.","wrong":"import INSERT from 'pg-sql-helpers'","symbol":"INSERT","correct":"import { INSERT } from 'pg-sql-helpers'"},{"note":"Correct for CJS, but preferred ESM syntax shown.","wrong":"const WHERE = require('pg-sql-helpers').WHERE","symbol":"WHERE","correct":"import { WHERE } from 'pg-sql-helpers'"},{"note":"Exported as uppercase but also lowercase alias exists; recommended uppercase.","wrong":"import { order_by } from 'pg-sql-helpers'","symbol":"ORDER_BY","correct":"import { ORDER_BY } from 'pg-sql-helpers'"},{"note":"sql template tag is from pg-sql, not pg-sql-helpers.","wrong":"import { sql } from 'pg-sql-helpers'","symbol":"sql","correct":"import { sql } from 'pg-sql'"},{"note":"Named export; used after a hardcoded WHERE clause.","wrong":null,"symbol":"AND","correct":"import { AND } from 'pg-sql-helpers'"}],"quickstart":{"code":"import { sql } from 'pg-sql';\nimport { INSERT, WHERE, ORDER_BY } from 'pg-sql-helpers';\nimport { Pool } from 'pg';\n\nconst pool = new Pool();\n\nasync function run() {\n  const name = 'john';\n  const ageFilter = { gt: 42 };\n  const sort = ['-age', 'name'];\n\n  const query = sql`\n    SELECT id, name, age\n    FROM users\n    ${WHERE({ name, age: ageFilter })}\n    ${ORDER_BY(sort)}\n  `;\n\n  const result = await pool.query(query);\n  console.log(result.rows);\n}\n\nrun().catch(err => console.error(err));","lang":"javascript","description":"Shows dynamic WHERE and ORDER BY using pg-sql-helpers with pg-sql template tag and pg pool."},"warnings":[{"fix":"Run: npm install pg-sql","message":"pg-sql must be installed alongside pg-sql-helpers; it is a peer dependency and not included automatically.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Consider alternatives like Slonik or Kysely for active development.","message":"Library is low maintenance; last release 2016, no updates for security or PostgreSQL version compatibility.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Ensure all objects in array have identical keys.","message":"INSERT with array of objects uses keys from first object; subsequent objects missing keys may cause SQL errors.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use hyphen directly; check whitespace (e.g., '- column' will not work).","message":"ORDER_BY accepts strings like '-column'; prefix '-' means descending. Ensure prefix is hyphen, not other minus signs.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'2016':51 'ad':65 'allow':54 'builder':75 'built':12 'cadenc':48 'claus':35,69 'concaten':39 'construct':26 'differenti':53 'dynam':6,68,77 'escap':78 'full':73 'helper':4,9,66 'ian':42 'insert':27 'interpol':79 'javascript':76 'key':52 'last':49 'librari':10 'like':23 'lodash':22 'lodash-lik':21 'low':46 'nativ':57 'order':30 'orm':71,80 'pg':2,17,62,81,83 'pg-sql':16,61,82 'pg-sql-helper':1 'pgsql':85 'postgr':86 'programmat':36 'provid':19 'queri':8,74 'releas':40,47 'sql':3,7,18,34,56,63,84 'sql-nativ':55 'storm':43 'string':38 'syntax':59 'taylor':44 'templat':58 'toolkit':24 'top':14 'unlik':70 'updat':28,50 'v0.3.7':11 'via':60 'without':37","created_at":"2026-06-05T17:00:29.628149+00:00","updated_at":"2026-06-05T17:00:29.628149+00:00","problems":[{"fix":"Install pg-sql: npm install pg-sql, and import { sql } from 'pg-sql'","cause":"pg-sql not installed or not imported correctly; query object missing sql template tag result.","error":"TypeError: Cannot read properties of undefined (reading 'text')"},{"fix":"Provide valid connection string or environment variables: DATABASE_URL","cause":"Missing or incorrect database credentials in pg Pool configuration.","error":"Error: password authentication failed for user"},{"fix":"Wrap helper calls inside sql`...` template literals only.","cause":"Using helpers outside of sql template tag; e.g., const clause = INSERT('users', {...}) used in string concatenation.","error":"SyntaxError: Unexpected identifier at column 1"},{"fix":"Add import: import { INSERT } from 'pg-sql-helpers'","cause":"Forgot to import helper from pg-sql-helpers.","error":"ReferenceError: INSERT is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"git://github.com/ianstormtaylor/pg-sql-helpers","github":"git://github.com/ianstormtaylor/pg-sql-helpers","docs":null,"changelog":null,"pypi":null,"npm":"pg-sql-helpers","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}