building extension with large string inserts

From: Tom van Tilburg <tom(dot)van(dot)tilburg(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: building extension with large string inserts
Date: 2017-07-05 13:21:48
Message-ID: CAP3PPDhTNJ59p16zwsMA=s-SeCQmi1eLAYPQ+_So34EP0bRkrg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am trying to build an extension where there is the need to insert large
strings consisting of javascript code. The easiest way to get these string
currently into a table is by using

\set varname `cat mycode.js`
INSERT INTO mytable VALUES (:'varname');

and run this from the psql client.
psql will escape the string nicely and stuff it into a text field.

This does not work with extensions since I cannot use \set anywhere else
than the psql client.

What would be a proper way to get this code into a table via an extension?
I've been working on generating INSERT statements for the extension's sql
file but it seems a tedious job to escape the code myself.

Best,
Tom

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2017-07-05 13:41:09 Re: Feature proposal, DBURL: psql pgsql://joe:p4zzw0rd@example.org:2345/dbname
Previous Message Albe Laurenz 2017-07-05 13:15:18 Re: Feature proposal, DBURL: psql pgsql://joe:p4zzw0rd@example.org:2345/dbname