Обсуждение: How to use psql -c?

Поиск
Список
Период
Сортировка

How to use psql -c?

От
Charles Haron
Дата:
Hello,

Can someone give me an example of how to use the -c option of psql? I can't
seem to get it to work.

Thanks,
Chuck


Re: How to use psql -c?

От
Sean Shanny
Дата:
from the command prompt:

psql -U password -d database -c "select tablename from pg_stats ;"

--sean

Charles Haron wrote:

>Hello,
>
>Can someone give me an example of how to use the -c option of psql? I can't
>seem to get it to work.
>
>Thanks,
>Chuck
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 6: Have you searched our list archives?
>
>               http://archives.postgresql.org
>
>
>


Re: How to use psql -c?

От
Michael Fuhr
Дата:
On Mon, Dec 29, 2003 at 01:49:00PM -0700, Charles Haron wrote:
>
> Can someone give me an example of how to use the -c option of psql? I can't
> seem to get it to work.

What are you doing and what are the results?  We can't tell you what's
wrong unless you show us what you're doing and what's happening.
Learning why something doesn't work can be just as useful as learning
how to make it work.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

Re: How to use psql -c?

От
"Anjan Dave"
Дата:
Chuck,

Report bugs to <pgsql-bugs@postgresql.org>.
-bash-2.05b$ psql -c 'select version();' template1
                                                 version

------------------------------------------------------------------------
---------------------------------
 PostgreSQL 7.2.3 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2
20020903 (Red Hat Linux 8.0 3.2-7)
(1 row)

-bash-2.05b$


Thanks,
Anjan

-----Original Message-----
From: Charles Haron [mailto:charles.haron@cognitive.com]
Sent: Monday, December 29, 2003 3:49 PM
To: pgsql-admin@postgresql.org
Subject: [ADMIN] How to use psql -c?


Hello,

Can someone give me an example of how to use the -c option of psql? I
can't seem to get it to work.

Thanks,
Chuck


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

               http://archives.postgresql.org

Re: How to use psql -c?

От
Charles Haron
Дата:

> From: Michael Fuhr <mike@fuhr.org>
> Date: Mon, 29 Dec 2003 14:06:13 -0700
> To: Charles Haron <charles.haron@cognitive.com>
> Cc: pgsql-admin@postgresql.org
> Subject: Re: [ADMIN] How to use psql -c?
>
> On Mon, Dec 29, 2003 at 01:49:00PM -0700, Charles Haron wrote:
>>
>> Can someone give me an example of how to use the -c option of psql? I can't
>> seem to get it to work.
>
> What are you doing and what are the results?  We can't tell you what's
> wrong unless you show us what you're doing and what's happening.
> Learning why something doesn't work can be just as useful as learning
> how to make it work.
>

My first problem was that I was using single quotes instead of double
quotes.  But now I have another problem.


The following command works as I want:
psql -c "DELETE FROM prg_dates_members WHERE confirm = 'f';" comfire

I want to be able to run the above command as a cron job.  I created a
script with the following command, but I get "ERROR:  Attribute 'f' not
found":
su - postgres -c 'psql  -c "DELETE FROM prg_dates_members WHERE confirm =
'f';" comfire'

What am I doing wrong?  Is there a better way to do this?

Thanks,
Chuck

> --
> Michael Fuhr
> http://www.fuhr.org/~mfuhr/
>


Re: How to use psql -c?

От
"David F. Skoll"
Дата:
On Mon, 29 Dec 2003, Charles Haron wrote:

> I want to be able to run the above command as a cron job.  I created a
> script with the following command, but I get "ERROR:  Attribute 'f' not
> found":
> su - postgres -c 'psql  -c "DELETE FROM prg_dates_members WHERE confirm =
> 'f';" comfire'

Why not avoid shell quoting problems by doing it like this:

su - postgres -c psql comfire <<EOF
DELETE FROM prg_dates_members WHERE confirm = 'f';
EOF

Regards,

David.

Re: How to use psql -c?

От
Charles Haron
Дата:

> From: "David F. Skoll" <dfs@roaringpenguin.com>
> Date: Mon, 29 Dec 2003 17:23:53 -0500 (EST)
> To: Charles Haron <charles.haron@cognitive.com>
> Cc: pgsql-admin@postgresql.org
> Subject: Re: [ADMIN] How to use psql -c?
>
> On Mon, 29 Dec 2003, Charles Haron wrote:
>
>> I want to be able to run the above command as a cron job.  I created a
>> script with the following command, but I get "ERROR:  Attribute 'f' not
>> found":
>> su - postgres -c 'psql  -c "DELETE FROM prg_dates_members WHERE confirm =
>> 'f';" comfire'
>
> Why not avoid shell quoting problems by doing it like this:
>
> su - postgres -c psql comfire <<EOF
> DELETE FROM prg_dates_members WHERE confirm = 'f';
> EOF
>

If I use this as is I get:
EOF: command not found

> Regards,
>
> David.
>


答复: [ADMIN] How to use psql -c?

От
周仁军
Дата:
           u's PATH have no problem?

-----原始邮件-----
发件人: pgsql-admin-owner@postgresql.org [mailto:pgsql-admin-owner@postgresql.org]代表 David F. Skoll
发送时间: 2003年12月30日 6:24
收件人: Charles Haron
抄送: pgsql-admin@postgresql.org
主题: Re: [ADMIN] How to use psql -c?


On Mon, 29 Dec 2003, Charles Haron wrote:

> I want to be able to run the above command as a cron job.  I created a
> script with the following command, but I get "ERROR:  Attribute 'f' not
> found":
> su - postgres -c 'psql  -c "DELETE FROM prg_dates_members WHERE confirm =
> 'f';" comfire'

Why not avoid shell quoting problems by doing it like this:

su - postgres -c psql comfire <<EOF
DELETE FROM prg_dates_members WHERE confirm = 'f';
EOF

Regards,

David.

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.556 / Virus Database: 348 - Release Date: 2003-12-26

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.556 / Virus Database: 348 - Release Date: 2003-12-26
 

Re: How to use psql -c?

От
Hans Peter Wiedau
Дата:
On Mon, Dec 29, 2003 at 02:37:57PM -0700, Charles Haron wrote:

> The following command works as I want:
> psql -c "DELETE FROM prg_dates_members WHERE confirm = 'f';" comfire
>
> I want to be able to run the above command as a cron job.  I created a
> script with the following command, but I get "ERROR:  Attribute 'f' not
> found":
> su - postgres -c 'psql  -c "DELETE FROM prg_dates_members WHERE confirm =
> 'f';" comfire'
>
> What am I doing wrong?  Is there a better way to do this?

The bash manual page says:

    A single quote may not occur between single quotes, even when
    preceded by a backslash.

So, try this one:

    su - postgres -c "psql -c \"DELETE FROM prg_dates_members WHERE confirm = 'f'\" comfire"

cu,

Hans Peter

--
 /////    Quelltext AG -- Professional Software Services
//   //   Hans Peter Wiedau <hpw-nl@quelltext.com>, CEO
//   //   Ostenhellweg 31, 44135 Dortmund, Germany
//  \\/   fon +49 231 9503750, fax +49 231 9503751
 ////\\   Web http://www.quelltext.com

Re: How to use psql -c?

От
Charles Haron
Дата:
On Dec 30, 2003, at 3:07 AM, Hans Peter Wiedau wrote:

> On Mon, Dec 29, 2003 at 02:37:57PM -0700, Charles Haron wrote:
>
>> The following command works as I want:
>> psql -c "DELETE FROM prg_dates_members WHERE confirm = 'f';" comfire
>>
>> I want to be able to run the above command as a cron job.  I created a
>> script with the following command, but I get "ERROR:  Attribute 'f'
>> not
>> found":
>> su - postgres -c 'psql  -c "DELETE FROM prg_dates_members WHERE
>> confirm =
>> 'f';" comfire'
>>
>> What am I doing wrong?  Is there a better way to do this?
>
> The bash manual page says:
>
>     A single quote may not occur between single quotes, even when
>     preceded by a backslash.
>
> So, try this one:
>
>     su - postgres -c "psql -c \"DELETE FROM prg_dates_members WHERE
> confirm = 'f'\" comfire"
>

    It works perfectly!  Thank you very much.

    Chuck

> cu,
>
> Hans Peter
>
> --
>  /////    Quelltext AG -- Professional Software Services
> //   //   Hans Peter Wiedau <hpw-nl@quelltext.com>, CEO
> //   //   Ostenhellweg 31, 44135 Dortmund, Germany
> //  \\/   fon +49 231 9503750, fax +49 231 9503751
>  ////\\   Web http://www.quelltext.com
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 8: explain analyze is your friend