Re: [SQL] bash & postgres

From: Erik Jones <ejones(at)engineyard(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Greenhorn <user(dot)postgresql(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org, pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] bash & postgres
Date: 2009-03-23 19:04:17
Message-ID: 71A6D593-FF9C-4F7E-B415-B54E6F9AA295@engineyard.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql


On Mar 23, 2009, at 7:05 AM, Tom Lane wrote:

> Erik Jones <ejones(at)engineyard(dot)com> writes:
>> On Mar 22, 2009, at 9:03 PM, Greenhorn wrote:
>>> How do I use \c (or any other psql commands beginning with a "\")
>>> in a
>>> bash script?
>
>> For multi-line input to a psql call in a bash (or any decent shell)
>> script, I'd use a here document:
>
> Or echo/cat the script into psql's stdin, if you prefer that type of
> notation. The reason you have to do this is that psql doesn't
> recognize
> backslash commands in a -c string. There's a school of thought that
> doesn't want us to allow multiple commands in a -c string, even.

Hmm... Apparently it does recognize them as long as the backslash is
the first character in the command string:

$ psql -c '\d' postgres
No relations found.
$ psql -c ' \d' postgres
ERROR: syntax error at or near "\"
LINE 1: \d
^

Is that expected behavior?

Erik Jones, Database Administrator
Engine Yard
Support, Scalability, Reliability
866.518.9273 x 260
Location: US/Pacific
IRC: mage2k

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message M L 2009-03-23 19:25:58 Re: The tuple structure of a not-yet-assigned record is indeterminate.
Previous Message Peter Willis 2009-03-23 18:13:48 Proper entry of polygon type data

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2009-03-23 19:55:13 Re: [SQL] bash & postgres
Previous Message DM 2009-03-23 15:04:14 Re: pg_restore error - Any Idea?