Forum Discussion
Connecting to Data: PostgreSQL (Function) error
- 5 months ago
Hi kcdavi01 ,
Believe that you problem is with the syntax of the Passed where you have added and additional '
Try the following:
PostgreSQL.Database("SERVER", "DATABASE", [Query="SELECT * FROM FUNCTION('" & StartDate & "', '" & EndDate & "', '" & DataType & "', '" & Status & "')"])
Hi kcdavi01 ,
Believe that you problem is with the syntax of the Passed where you have added and additional '
Try the following:
PostgreSQL.Database("SERVER", "DATABASE", [Query="SELECT * FROM FUNCTION('" & StartDate & "', '" & EndDate & "', '" & DataType & "', '" & Status & "')"])
- kcdavi015 months agoFrequent Visitor
Hi Miguel,
Hope all is well! Thanks a bunch for providing that solution! I was able to final get past that error message!
I did have a bit of a follow-up if you can address of course:
- My original script had very static values for its parameters. I was wondering how I could target everything , like for example all of the Status options vs just 1
- Passed
- Failed
- All
- In Progress
- Pending
Is there someway I can get all the data or would I have to write out each one? And ifs its to be written out, what should the format be?
Thanks again for your help!
- MFelix5 months agoSuper User
Hi kcdavi01 ,
Not sure how you have everything setup and how the coede works in terms of the PostGres SQL but one option can be to turn the initial SQL statment into a table and use the values on the table to get the SQL query to run follow these steps:
- Create a table with the status column
- Now add a new column to that table with the following code:
let StartDate = "01/01/2026", EndDate = "01/01/2026", DataType = "Received", Status = [Status], Source = PostgreSQL.Database("SERVER", "DATABASE", [Query="SELECT * FROM FUNCTION('" & StartDate & "', '" & EndDate & "', '" & DataType & "', '" & Status & "')"]) in SourceIf you see the Status value is now replaced by the Column you use rthen you can just expand your new column with all your data:
Another option is to do a function and use it on the new column:
let ParameterValues = (Status as text) => let StartDate = "01/01/2026", EndDate = "01/01/2026", DataType = "Received", Source = PostgreSQL.Database("SERVER", "DATABASE", [Query="SELECT * FROM FUNCTION('" & StartDate & "', '" & EndDate & "', '" & DataType & "', '" & Status & "')"]) in Source in ParameterValuesThen add the custom function:
The rest is equal.
Using a function instead of writing the code directly on the table is easier for maintenance in the future.