Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
  • Sign in / Register
M
massive-js
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 10
    • Issues 10
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 2
    • Merge requests 2
  • Requirements
    • Requirements
    • List
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Dian Fay
  • massive-js
  • Issues
  • #709

Closed
Open
Created Apr 02, 2020 by mo@ghammed

onConflictUpdate doesn't allow expressions

Summary

Postgres unique indices support expressions (like lower(name)). It seems currently impossible to use such constraints in conjunction with massive's insert onConflictUpdate because it automatically puts quotes around the fields.

Example

Database setup

CREATE TABLE things (
  id SERIAL PRIMARY KEY,
  stuff TEXT,
  name TEXT
);

CREATE UNIQUE INDEX CONCURRENTLY stuff_name_idx
ON things (stuff, lower(name));

Code demonstrating the behavior

db.things.insert({ stuff: 'stuff', name: 'thing' });
db.things.insert({ stuff: 'stuff', name: 'Thing' }, { onConflictUpdate: ['stuff', 'lower(name)'] });

Expected behavior

A conflict causes the thing to be updated.

Actual behavior

An error occurs, stating that "lower(name)" is not a column of the things table:

InternalServerError: column "lower(name)" does not exist

Additional context

We were able to work around this by using this hack:

db.things.insert({ stuff: 'stuff', name: 'Thing' }, { onConflictUpdate: ['stuff", lower(name), "stuff'] });
Edited Apr 02, 2020 by mo
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking