Discussion:
How to use psql -c?
(too old to reply)
Charles Haron
2003-12-29 20:49:00 UTC
Permalink
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
Sean Shanny
2003-12-29 20:57:46 UTC
Permalink
from the command prompt:

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

--sean
Post by 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
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ***@postgresql.org so that your
message can get through to the mailing list cleanly
Michael Fuhr
2003-12-29 21:06:13 UTC
Permalink
Post by Charles Haron
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/

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Charles Haron
2003-12-29 21:37:57 UTC
Permalink
Date: Mon, 29 Dec 2003 14:06:13 -0700
Subject: Re: [ADMIN] How to use psql -c?
Post by Charles Haron
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/
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
David F. Skoll
2003-12-29 22:23:53 UTC
Permalink
Post by Charles Haron
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
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
Charles Haron
2003-12-29 22:53:59 UTC
Permalink
Date: Mon, 29 Dec 2003 17:23:53 -0500 (EST)
Subject: Re: [ADMIN] How to use psql -c?
Post by Charles Haron
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
su - postgres -c 'psql -c "DELETE FROM prg_dates_members WHERE confirm =
'f';" comfire'
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.
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Hans Peter Wiedau
2003-12-30 10:07:09 UTC
Permalink
Post by Charles Haron
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
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-***@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
Charles Haron
2003-12-30 17:28:38 UTC
Permalink
Post by Hans Peter Wiedau
Post by Charles Haron
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
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?
A single quote may not occur between single quotes, even when
preceded by a backslash.
su - postgres -c "psql -c \"DELETE FROM prg_dates_members WHERE
confirm = 'f'\" comfire"
It works perfectly! Thank you very much.

Chuck
Post by Hans Peter Wiedau
cu,
Hans Peter
--
///// Quelltext AG -- Professional Software Services
// // 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
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Anjan Dave
2003-12-29 20:54:21 UTC
Permalink
Chuck,

Report bugs to <pgsql-***@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:***@cognitive.com]
Sent: Monday, December 29, 2003 3:49 PM
To: pgsql-***@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

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings
Loading...