vitaly-t/pg-promise

Is it possible to enum and timestamp using pgp.helpers.update?

amanattrish opened this issue · 1 comments

Expected behavior

pgp.helpers.update should be able to update enum and timestamp.

I have a table ("myTable") it has following columns

id (varchar)
comparator (type enum named as comparator_type with values ['eq', 'ne', 'leq', 'geq', 'gt', 'lt'])
updatedAt (timestamp)

The entries to update are

entries = [
    {
        id: "someId",
         comparator: "gt",
        updatedAt: new Date().toISOString()
    }
]
// Using pgp.helpers.update
const updateQuery = pgp.helpers.update(entries, ["?id", "comparator", "updatedAt"], "myTable") + '  WHERE v.id = t.id';
console.log(updateQuery);

// printing it here for reference
/**
* update "myTable" as t set "comparator"=v."comparator","updatedAt"=v."updatedAt" from (values('someId','gt','0.92','2023-02-17T19:46:38.723Z')) as v("id","comparator","updatedAt") WHERE v.id = t.id
**/

Actual behavior

It is not updating type enum and timestamp. This is following error I'm getting

Steps to reproduce

The following code is being used to run the generated query

await pgDb.any(updateQuery);

The following error I'm getting

{
    "name": "error",
    "severity": "ERROR",
    "code": "42804",
    "hint": "You will need to rewrite or cast the expression.",
    "position": "112",
    "file": "parse_target.c",
    "line": "587",
    "routine": "transformAssignedExpr",
    "query": "<query above>"
}

When I tried to run the same query in Dbever, it starts to give me the following,

ERROR: column "comparator" is of type comparator_type but expression is of type text. Hint: You will need to rewrite or cast the expression.

if I change the "comparator"=v."comparator" to "comparator"='gt', then it given me next error that is

ERROR: column "updatedAt" is of type timestamp without time zone but expression is of type text. Hint: You will need to rewrite or cast the expression.

SO clearly, the query generated by pg-promise is not working.

Environment

  • Version of pg-promise: 11.2.0
  • OS type (Linux/Windows/Mac): Linux
  • Version of Node.js: v16.19.0
Link to stackoverflow issue I created - https://stackoverflow.com/questions/75485625/is-it-possible-to-enum-and-timestamp-using-pgp-helpers-update

See my comments on StackOverflow, no need to republish here ;)

Closing as invalid-use, since you are not using casting, even though the very error tells you that you should.