pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How to use psql -c?
9+ messages / 6 participants
[nested] [flat]

* How to use psql -c?
@ 2003-12-29 20:49  Charles Haron <charles.haron@cognitive.com>
  0 siblings, 2 replies; 9+ messages in thread

From: Charles Haron @ 2003-12-29 20:49 UTC (permalink / raw)
  To: pgsql-admin

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




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: How to use psql -c?
@ 2003-12-29 20:54  Anjan Dave <adave@vantage.com>
  0 siblings, 0 replies; 9+ messages in thread

From: Anjan Dave @ 2003-12-29 20:54 UTC (permalink / raw)
  To: Charles Haron <charles.haron@cognitive.com>; pgsql-admin

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



^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: How to use psql -c?
@ 2003-12-29 20:57  Sean Shanny <shannyconsulting@earthlink.net>
  parent: Charles Haron <charles.haron@cognitive.com>
  1 sibling, 0 replies; 9+ messages in thread

From: Sean Shanny @ 2003-12-29 20:57 UTC (permalink / raw)
  To: Charles Haron <charles.haron@cognitive.com>; +Cc: pgsql-admin

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
>
>  
>




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: How to use psql -c?
@ 2003-12-29 21:06  Michael Fuhr <mike@fuhr.org>
  parent: Charles Haron <charles.haron@cognitive.com>
  1 sibling, 1 reply; 9+ messages in thread

From: Michael Fuhr @ 2003-12-29 21:06 UTC (permalink / raw)
  To: Charles Haron <charles.haron@cognitive.com>; +Cc: pgsql-admin

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/



^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: How to use psql -c?
@ 2003-12-29 21:37  Charles Haron <charles.haron@cognitive.com>
  parent: Michael Fuhr <mike@fuhr.org>
  0 siblings, 2 replies; 9+ messages in thread

From: Charles Haron @ 2003-12-29 21:37 UTC (permalink / raw)
  To: pgsql-admin



> 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/
> 




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: How to use psql -c?
@ 2003-12-29 22:23  David F. Skoll <dfs@roaringpenguin.com>
  parent: Charles Haron <charles.haron@cognitive.com>
  1 sibling, 1 reply; 9+ messages in thread

From: David F. Skoll @ 2003-12-29 22:23 UTC (permalink / raw)
  To: Charles Haron <charles.haron@cognitive.com>; +Cc: pgsql-admin

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.



^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: How to use psql -c?
@ 2003-12-29 22:53  Charles Haron <charles.haron@cognitive.com>
  parent: David F. Skoll <dfs@roaringpenguin.com>
  0 siblings, 0 replies; 9+ messages in thread

From: Charles Haron @ 2003-12-29 22:53 UTC (permalink / raw)
  To: David F. Skoll <dfs@roaringpenguin.com>; +Cc: pgsql-admin



> 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.
> 




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: How to use psql -c?
@ 2003-12-30 10:07  Hans Peter Wiedau <hpw-nl@quelltext.com>
  parent: Charles Haron <charles.haron@cognitive.com>
  1 sibling, 1 reply; 9+ messages in thread

From: Hans Peter Wiedau @ 2003-12-30 10:07 UTC (permalink / raw)
  To: pgsql-admin

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



^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: How to use psql -c?
@ 2003-12-30 17:28  Charles Haron <charles.haron@cognitive.com>
  parent: Hans Peter Wiedau <hpw-nl@quelltext.com>
  0 siblings, 0 replies; 9+ messages in thread

From: Charles Haron @ 2003-12-30 17:28 UTC (permalink / raw)
  To: pgsql-admin


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




^ permalink  raw  reply  [nested|flat] 9+ messages in thread


end of thread, other threads:[~2003-12-30 17:28 UTC | newest]

Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-12-29 20:49 How to use psql -c? Charles Haron <charles.haron@cognitive.com>
2003-12-29 20:57 ` Sean Shanny <shannyconsulting@earthlink.net>
2003-12-29 21:06 ` Michael Fuhr <mike@fuhr.org>
2003-12-29 21:37   ` Charles Haron <charles.haron@cognitive.com>
2003-12-29 22:23     ` David F. Skoll <dfs@roaringpenguin.com>
2003-12-29 22:53       ` Charles Haron <charles.haron@cognitive.com>
2003-12-30 10:07     ` Hans Peter Wiedau <hpw-nl@quelltext.com>
2003-12-30 17:28       ` Charles Haron <charles.haron@cognitive.com>
2003-12-29 20:54 Re: How to use psql -c? Anjan Dave <adave@vantage.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox