question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

using postgres functions from knex

See original GitHub issue

so I’m using timestamptz with specificType I need to be able to use postgres’s native date-time functions to set a default.

I tried

table.specificType('currentTime', 'timestamptz').defaultTo('now()'); 

but that ends up setting the default value to the most current time stamp as a static value. How do i pass along postgresql functions.

basically I want to do this, But in knex.

ALTER TABLE "public"."users" ADD COLUMN "currentTime" TIMESTAMP WITH TIME ZONE DEFAULT now();

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

11reactions
knownasilyacommented, Feb 28, 2014

Btw, for anyone having this same issue, the fix (workaround?) is to wrap that value in a knex.raw, so:

knex(tableName).insert({
  id: 1,
  name: 'Test',
  geom: knex.raw('ST_Multi(ST_GeomFromGeoJSON(\'..\'))')
}).then(...);
0reactions
knownasilyacommented, Jun 4, 2014

@tgriesser is on a roll today!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Calling functions on PostgreSQL #2044 - knex/knex - GitHub
Hi, Is there a way calling postgres functions without using knex.raw() in order to get the result parsed to an object using the...
Read more >
Knex Query Builder
The heart of the library, the knex query builder is the interface used for building and executing standard SQL queries, such as select...
Read more >
Knex.js and Postgres - Magistrate
Knex.js is a SQL query builder based on Laravel Query Builder. It supports a handful of different databases, most importantly Postgres.
Read more >
How to call custom function from postgresql use objection js ...
I found the answer. I use objection js to call knex raw. let _data = await Model.knex().raw('select * from function_name(?, ?)
Read more >
Setting up a Node API with Postgres and Knex
In this article, I would be setting up a Node project with Postgres database and Knex query builder. What is Knex. Knex.js is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found