The PostgreSQL pg-promise function that handles void operations

After running a PostgreSQL function that has a RETURNS void statement, I noticed that db.none() throws an error message saying "No return data was expected.".

As a workaround, I decided to use the db.one() method instead, which successfully returns an object with the value { PS_name: '' }.

Is it common for PostgreSQL void functions to actually provide an empty object as a return value? How should void functions be properly handled when using pg-promise?

Answer №1

The answer below is outdated now, as PostgreSQL v11 has introduced support for proper stored procedures. The method proc can now only call a stored procedure using the new CALL syntax.


How should void functions be handled with pg-promise in the most appropriate manner?

Utilize the proc Database method.

db.proc('proc_name', [param1, param2,...])
    .then(data => {
        /* data could be null or an object */
    })
    .catch(error => {
        /* error handling */
    });

UPDATE

When using proc, how can parameter types be specified to resolve errors like

function foo(unknown) does not exist
? For example, if I try db.proc('foo($1::int2[])', x), it gives a syntax error at or near "(".

You cannot specify parameter types with the proc method, which is designed for simplicity. If your call requires SQL type casting, you should execute it as a regular query with casting inside the template:

db.oneOrNone('SELECT * FROM proc_name($1::int2[], $2, ...)', [param1, param2,...])
    .then(data => {
        /* data may be null or an object */
    })
    .catch(error => {
        /* handle any errors */
    });

In this context, the oneOrNone method provides similar result expectations as the proc method.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Why isn't my Vue2 data updating in the HTML?

Starting my journey with Vue, I have been finding my way through the documentation and seeking support from the Vue community on Stack Overflow. Slowly but steadily, I am gaining a better understanding of how to create more complex components. The issue I ...

issue with mongoose.save() not properly saving certain fields

As someone new to Node.js and Express, I may not be very clear in my explanation. I am currently working on creating a mini Twitter clone using MongoDB. When a user submits a tweet (referred to as "mew" in my application), it triggers a POST request. Alth ...

What is the best way to extract the URL value and insert it into a text box?

After submitting the form, the URL looks like this: from=Paris%2C+France&to=Rome%2C+Italy On the new page, I need the value of 'from' to be inserted into the following input field: <input id="from" class="form-control" type="text" name= ...

Developing a counter/timer feature in a web application using PHP and MySQL

I am currently working on a form that submits data to a database with the possibility of the issue being either 'resolved' or 'notresolved'. My goal is to create a timer that starts counting as soon as the form is submitted and the issu ...

Exploring the power of nesting methods within *ngIf

project[col.field][selectedUserRole.value].join(',').length When attempting to use the code above within *ngIf or inside curly braces {{}}, an error occurs: ERROR TypeError: Cannot read property 'join' of undefined This error indic ...

Vue: Optimizing JSON response filtering

I am struggling with filtering a JSON response using Vue. return this.offers.filter(type => type.offers == 'Junior'); When I keep it as return this.offers, the following is displayed in my HTML: {"-MN5agCddYAdy7c8GSSz": { "comp ...

What steps can be taken after the addClass function has been triggered?

I am trying to achieve a functionality where upon clicking a button, a div will add a class that changes its width to 150px. However, I want something to be shown in console.log only after the div has become 150px in width. Can anyone assist me in achievin ...

Verify if the textbox is empty

Is there a way to verify that the input field with type "text" is not empty before moving to the next page? <input TYPE="text" name="textbox2" align="center"> ........ function HomeButton() { <!--if both textbox1 and textbox2 values are not ...

Is there a way to display a foundation.css drop-down menu using jQuery?

After attempting to create a navigation bar using foundation.css, I encountered an issue where the sub-menu does not appear when hovering over it with the mouse. The main question at hand is how to display the sub-menu of test on this specific webpage. D ...

Breaking down objects and setting default values

In need of assistance with resolving an issue related to default parameters and object destructuring. The 'product' object that I am working with has the following structure: { name: "Slip Dress", priceInCents: 8800, availableSizes ...

Whenever I attempt to start the server using npm run server, I encounter the following error message: "Error: Unable to locate module './config/db'"

This is the server.jsx file I'm working with now: Take a look at my server.jsx file Also, here is the bd.jsx file located in the config folder: Check out the db.jsx file Let me show you the structure of my folders as well: Explore my folder structur ...

Issue with forEach function not executing in Next.js useEffect

I am struggling to present all the 'posts' from my database in separate divs. The code successfully retrieves the posts and stores them in an array called posts. However, I encounter a problem when trying to loop through the posts using the forEa ...

Creating individual subpages with unique URLs for each post automatically using NodeJS

I built a dynamic home page that showcases posts fetched from a MySQL database using JavaScript fetch requests. for(var a = 0; a < reslength; a++){ html += `<div class="post">`; html += `<div class="meta" ...

Building a versatile JavaScript library for both Angular applications and server-side Node.js environments

I am interested in developing a JavaScript library that can be utilized in both web browsers with Angular and on servers with Node.js. I am facing some confusion on how to set up this project. I want to incorporate TypeScript, but my familiarity lies more ...

Receiving data through multiple ajax calls nested within another ajax call

Hello everyone, I am diving into the world of AJAX/jQuery and would appreciate your patience as I try to navigate through it. I have an interesting challenge ahead so let's see how we can tackle it together ...

Refresh the DOM following a jQuery load operation

Recently, I integrated the Jquery Load($('body').load('/some.html')) function into my application. There are plenty of other jquery codes in my application initialized as $('#id'). Instead of transforming all these codes into ...

What is the best approach for managing client-side routes when a page refresh displays the backend Rails route instead?

After deploying my SPA to Render, I encountered an issue. My application comprises a React frontend with Redux and a Rails backend. When the app initializes, it correctly displays the frontend route in the browser. Subsequent navigation without refreshing ...

Discover the process for finding a Youtube Channel Name with querySelectorAll

OUTPUT : Console URL : https://www.youtube.com/feed/trending?gl=IN document.querySelectorAll('a[class="yt-simple-endpoint style-scope yt-formatted-string"]')[0].innerText; document.querySelectorAll('a[class="yt-simple-endpoi ...

Tips for creating a curved shape using fabric.js

I am encountering an issue while trying to draw an arc using a circle with a start and end angle in my code. Here is the snippet I am working with: var circle = new fabric.Circle({ radius: 30, left: 20, top: 20, fill: " ...

How to toggle the visibility of specific div elements within a v-for loop depending on their content?

I am working on a scenario where I have a collection of objects displayed in a v-for loop. Each object has a specific key value pair, and I want the user to be able to toggle a button outside the loop to show or hide elements based on that key value. Initi ...