<div><div dir="rtl"><div>This is a join in a middle of query.<br><br><br></div>
<div>How can I use dynamic SQL in the middle of query?</div></div><section class="cust_msg_end"></section><blockquote style="margin:0;margin-bottom:20px;border-top:1px solid #e0e0e0;"><br>ב מאי 15, 2017 20:26, David G. Johnston כתב:<blockquote style="margin:0;margin-bottom:20px;border-top:1px solid #e0e0e0"><div dir="ltr"><div style="font-family:arial,helvetica,sans-serif"><span style="font-family:arial,sans-serif">On Mon, May 15, 2017 at 10:02 AM, Nick Dro </span><span dir="ltr" style="font-family:arial,sans-serif"><<a href="mailto:postgresql(at)walla(dot)co(dot)il" target="_blank">postgresql(at)walla(dot)co(dot)il</a>></span><span style="font-family:arial,sans-serif"> wrote:</span><br></div><div><div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="rtl"><div dir="rtl">
<div dir="ltr">Hi, <br>I'm new to postgresql and couldn't find answer to this situation anywhere. <br>I asked this here: <br><a href="http://stackoverflow.com/questions/43984208/coditional-join-of-query-using-postgresql" rel="nofollow" target="_blank">http://stackoverflow.com/<wbr>questions/43984208/coditional-<wbr>join-of-query-using-postgresql</a><br><br>I hope there is a better solution rather than creating two separated functions :(</div>
</div></div></blockquote></div><br></div><div><div style="font-family:arial,helvetica,sans-serif">Generate the SQL itself in a string then execute the string. Its called "Dynamic SQL".</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div><font face="arial, helvetica, sans-serif"><a href="https://www.postgresql.org/docs/9.6/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN">https://www.postgresql.org/docs/9.6/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN</a></font><br></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">David J.</font></div><br></div></div>
<br></blockquote></blockquote><br></div>