In one my last blogs I came up with the idea of writing some Vim script for PostgreSQL so that people can edit data fast and easily directly in Vim. The goal is to export a table directly to Vim, modify it and load it back in. This can come in handy when you want to edit a configuration table or some other small data set. Using INSERT / UPDATE / DELETE can be quite a lot of work.
Importing into Vim is basically not too much of an issue – but, exporting data back to PostgreSQL has kept me and my fellow here in office (Attila Max Ruf) pretty occupied mentally.
The weekend has finally left us with the following procedures:
1 2 3 |
:call PSQLInit({'host': , 'port': …, 'db': …, 'usr': …, 'passwd': …, }) :call PSQLCopyTable( 't_test', [ 'db', [, truncfile: 0 ]] :call PSQLCopySave('t_test' [, 'db']) |
The PSQLInit call will initialize the editor and provide information about where to find what and so on. Then there is PSQLCopyTable to load the data from PostgreSQL to Vim (in COPY format). Once you have edited the data you can call PSQLCopySave to pump the data back in.
Note that this will simply replace the content of the entire table.
In order to receive regular updates on important changes in PostgreSQL, subscribe to our newsletter, or follow us on Facebook or LinkedIn.
+43 (0) 2622 93022-0
office@cybertec.at
You are currently viewing a placeholder content from Facebook. To access the actual content, click the button below. Please note that doing so will share data with third-party providers.
More InformationYou are currently viewing a placeholder content from X. To access the actual content, click the button below. Please note that doing so will share data with third-party providers.
More Information