3

I encountered the dilemma of needing to run some psql console commands because a colleague needed to use psql's \i directive in a saved script to execute additional SQL-statements from another file, but I noticed that psql was choking on these files because of some extra garbage characters that pgAdmin was writing to them:

psql:C:/tmp/junk.sql:3: ERROR:  syntax error at or near "CREATE"
LINE 1: CREATE TABLE junktable (

psql is needed here because \i is not an official part of SQL, so it won't run if you send a command like that directly to the database's interpreter, even if it had a way of getting to the files on your local disk.

To keep things simple, I wanted to find a way to allow the PgAdmin's sql-editor to play nice with Postgres so I'm not suddenly telling other people at work to download and install another editor just to get around this; they already know and use pgAdmin.

Related questions:

1 Answer 1

2

Happily, there's a solution that doesn't require alterations to psql.exe or anything like that.

If you poke around in PgAdmin III's options (File -> Options), under the "Query Tool" heading in "Query file", you'll find a checkbox toggle option for "Write BOM for UTF files."

PgAdmin III options: Query tool: Query file

Once you hit OK, you should be able to save out files from PgAdmin which work with the packaged version of psql.exe. If you have existing files which had the UTF BOM-table present which was preventing psql from reading them properly, you can load them from PgAdmin's SQL-query editor and then just use the Save As option to save over them in place. It should also work to just make a small change like adding a comment-line and doing a regular Save (ctrl-S).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .