The query successfully executes in PGAdmin, but encounters an error when running on the server (node\localhost

We have encountered an issue with our node server and pg module when querying our postgres database. While the query executes successfully in PGAdmin, it throws errors on our server (js). Can anyone provide insights into what might be causing this discrepancy and how we can resolve it?

Below is the query in question:

 SELECT DISTINCT waswindows.computername as servername, waswindows.appcode, ipaddress, result, WASInventorywindows.uploaddate
    FROM public.waswindows JOIN WASInventorywindows
    ON (waswindows.appcode = $1 OR waswindows.computername LIKE $2 OR WASInventorywindows.appcustodian LIKE $2)
    AND position(WASInventorywindows.servername in waswindows.computername) > 0
    AND result = 'FAILED' AND waswindows.uploaddate = (SELECT MAX(uploaddate) FROM waswindows)

The query runs smoothly in PGAdmin (after replacing $1 and $2 with parameters), however a similar query runs without any errors both in PGAdmin and the Server. Below is an excerpt from the error log:

PARAMS ARE: Alex  AND   %Alex%
{ error: syntax error at or near "JOIN"
    at Connection.parseE (C:\Users\326009107.MAPLE\Desktop\Compliance\GHSRiskTSSCompliance\node_modules\pg\lib\connection.js:567:11)
    at Connection.parseMessage (C:\Users\326009107.MAPLE\Desktop\Compliance\GHSRiskTSSCompliance\node_modules\pg\lib\connection.js:391:17)
    at Socket.<anonymous> (C:\Users\326009107.MAPLE\Desktop\Compliance\GHSRiskTSSCompliance\node_modules\pg\lib\connection.js:129:22)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:548:20)
  name: 'error',
  length: 94,
  severity: 'ERROR',
  code: '42601',
  detail: undefined,
  hint: undefined,
  position: '143',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'scan.l',
  line: '1086',
  routine: 'scanner_yyerror' }
C:\Users\326009107.MAPLE\Desktop\Compliance\GHSRiskTSSCompliance\API\WAS\getdata.js:44
                                set.push(results.rows);

Despite attempting various adjustments such as using aliases, changing the order of items, and modifying the database string, the issue persists.

Answer №1

After encountering a common issue, I decided to share the solution for anyone facing the same problem. When combining strings in a query on a website, it is essential to include spaces between them. Here's an example:

"SELECT DISTINCT name, address, city" +
"FROM public.city JOIN employees"...

The above code snippet contains an error. The correct version should be formatted like this:

"SELECT DISTINCT name, address, city" +
" FROM public.city JOIN employees"...
^_________be sure to add this space_______

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

Dynamically extract attribute columns from nested JSON structures in PostgreSQL

When dealing with hierarchical JSON data as a table in PostgreSQL, hard coding the column names may not be practical, especially with a large number of columns. Here is a sample JSON structure: { "NODES": [ { "DESC_D": &quo ...

How can you iterate over the input elements that are currently visible within a form using Javascript?

Is there a way to clear the values of all visible input fields in a form using JavaScript? I'm currently struggling with setting text inputs to empty as they come out as undefined. Any suggestions on how to achieve this? ...

Ensure that the page has completely loaded using WebdriverJS

Is there a reliable method to ensure that a page has fully loaded using selenium-webdriver in JavaScript? I came across this similar query, but I require an implementation specifically in JavaScript. var webdriver = require('selenium-webdriver') ...

TS type defined by JS constants

I am currently working on a project that involves both JavaScript and TypeScript. I am trying to find a solution to reduce code duplication when using JavaScript string constants by converting them into TypeScript types. For example, let's say I have ...

Node for Angular forms workflow

I'm on the hunt for workflow nodes with forms that open when the user clicks on them. While I've come across a few options, not all of them are open source. Can you point me towards some open source (simple and basic) alternatives? Here's w ...

Generating objects dynamically using an array of paths in dot notation

Is it possible to dynamically generate an object with an array of strings in dot notation? The idea is to construct a JSON object from a CSV file, filter the properties, and create a new JSON object. Let's say we want to pass something like this... ...

Efficiently managing modules with requirejs and Backbone.Marionette

After organizing the file structure of my web app, utilizing RequireJs and Backbone.Marionette, it now looks like this: |- main.js |- app.js |- /subapp1 |- subapp1.js |- subapp1.router.js |- /subapp2 |- subapp2.js | ...

Managing websites on Android when the keyboard is displayed

I am currently facing an issue with my webpage on Android (Galaxy SIII). The problem occurs when visitors try to enter their email in the form at the bottom of the page. The keyboard becomes visible, causing the design to look messy. When using Chrome, the ...

Why do I keep receiving the error message "Cannot set property of undefined"?

In the midst of a small project that involves utilizing nuxt, js, and axios, I encountered an issue when attempting to assign the response data to my formFields object. Despite having declared formFields within the data section, I kept receiving an error m ...

Adding a URL link to a mentioned user from angular2-mentions within an Angular 4 application can be achieved in the following way:

Need help with adding a URL RouterLink to mention a user using angular2-mentions. This is the code snippet I currently have: <div class="col-sm-12"> <input type="text" [mention]="contactNames" [mentionConfig]="{triggerChar:'@',maxI ...

Keep an eye out for classes that are added dynamically

Are there any event listeners available that can watch for and execute code when a class is dynamically added to an element? I'm working within a WordPress CMS and a plugin I am using adds classes dynamically. I want to be able to detect this and then ...

Issue with hidden input field not displaying array on submission

I need assistance with adding filenames that have been uploaded to an array in a hidden input field within a form. Here's what I currently have in my form: <input type="hidden" name="myFiles[]" id="myFiles" value=""> This is how my file upload ...

Why is the parent element not receiving the event in Vue.JS? Is it necessary for the parent to be a custom component in order to receive the

I'm new to Vue.js. I used to think that Events worked by bubbling up through the DOM tree until caught by a parent element. However, something seems to be off. The code below isn't functioning as expected - there are no errors or warnings, and in ...

Displaying a component in a router view based on specific conditions

Currently, I am delving into the world of Vue3 as a newcomer to VueJS. In my project, there is an App.vue component that serves as the default for rendering all components. However, I have a Login.vue component and I want to exclude the section when rende ...

Using the select method in JavaScript arrays

Are the functionalities of JavaScript and Ruby similar? array.select {|x| x > 3} Could it be done like this instead: array.select(function(x) { if (x > 3) return true}) ...

Switching from Vanilla JS to Vue.js, dealing with querySelector problems

Seeking assistance with transforming the following CodePen example to a Vue.js component: https://codepen.io/kjbrum/pen/qooQJJ While attempting to incorporate this.$nextTick for handling DOM manipulation, I'm encountering challenges in making it func ...

define a variable within a v-for loop

Example of Code <div v-for="item in dataItems"> <div v-if="enableEdit"> <input type="text" v-model="name"> </div> <div v-else> {{name}} </div> <button @click="enableEdit = true">click</button> This ...

Combining multiple datasets in Javascript with a constant value of [0] to calculate the sum

Being a beginner, I am seeking assistance with my variable chartdata that serves as a basis: var chartdata = { labels: [ "Bar 1", "Bar 2", "Bar 3", "Bar 4", ], datasets: [ { label: "Green data", type: "bar", dat ...

developing a stand-alone job listings feature

Our website features a job postings page that our clients are interested in incorporating into their own websites. This would allow applicants to easily apply for jobs directly on the client's site, with the information being saved in our system. One ...

Issue with extraneous event being activated upon bootstrap collapse button usage

I have implemented a functionality using Bootstrap 5.2 where I have two buttons that can hide content by utilizing the Bootstrap collapse plugin. <div class="col-12 col-sm-auto"> <span class="pe-2"> ...