I am working on sql script in which i need to insert record in the db only if record is missing in the table , if record do exists in the table i need to update the template Here is my sql query
insert into deployment.nodes values('sind','11', now(),'temp',
'<table id="producttable">
<thead>
<tr>
<td>UPC_Code</td>
<td>Product_Name</td>
</tr>
</thead>
<tbody>
<!-- existing data could optionally be included here -->
</tbody>
</table>
<template id="productrow">
<tr>
<td class="record"></td>
<td></td>
</tr>
</template> ') on conflict on constraint nodes_pkey
DO UPDATE SET latest=now(), status='active',
agent='<table id="producttable">
<thead>
<tr>
<td>UPC_Code</td>
<td>Product_Name</td>
</tr>
</thead>
<tbody>
<!-- existing data could optionally be included here -->
</tbody>
</table>
<template id="productrow">
<tr>
<td class="record"></td>
<td></td>
</tr>
</template>'
This sql script is working fine for me but i want to use HTML stuff in a variable to minimize the length of sql script.
lets say
var template = '<html> .... </html>' and then query will be like
insert into deployment.nodes values('sind','11', now(),'temp',template) on conflict on constraint
nodes_pkey DO UPDATE SET latest=now(), status='active',agent=template
set agent = EXCLUDED.agentSee here: postgresql.org/docs/current/sql-insert.html