Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hi all, I hope all is well! I have a client that would like to connect to a PostGreSQL function (vs a table) but we're running into an error message when trying to connect via a Power Query M script:
let
StartDate = "01/01/2026",
EndDate = "01/01/2026",
DataType = "Received",
Status = "Passed",
Source = PostgreSQL.Database("SERVER", "DATABASE", [Query="SELECT * FROM FUNCTION('" & StartDate & "', '" & EndDate & "', '" & DataType & "', '" & Status & "'')"])
in
Source
DataSource.Error: PostgreSQL: 42601: unterminated quoted string at or near "'Passed'')"
Details:
DataSourceKind=PostgreSQL
DataSourcePath=SERVER
Message=42601: unterminated quoted string at or near "'Passed'')"
ErrorCode=-2147467259
What should I enter in order to access the data? Is it safe to assume I need a custom Power Query M script vs using the standard PostGresSQL connector?
Thanks a bunch in advance!
Solved! Go to Solution.
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 & "')"])
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsHi @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 & "')"])
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsHi 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:
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!
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:
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
Source
If 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 ParameterValues
Then 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.
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsIf you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.
| User | Count |
|---|---|
| 47 | |
| 44 | |
| 40 | |
| 20 | |
| 15 |
| User | Count |
|---|---|
| 70 | |
| 68 | |
| 32 | |
| 27 | |
| 25 |