use of IN() with literals

Started by Dennis Gearonalmost 16 years ago4 messagesgeneral
Jump to latest
#1Dennis Gearon
gearond@sbcglobal.net

I'm trying to use the following script: (to give command line ability to change grant on all tables in public in a database)

psql -t -c “SELECT ‘GRANT $1 ON public.’ || t.relname || ‘ TO $2;’ from pg_class t, pg_namespace s WHERE t.relkind IN (‘r’, ‘v’, ‘S’) AND t.relnamespace=s.oid AND s.nspname=’public’;” $3 | psql $3

and it always fails at the "IN(‘r’, ‘v’, ‘S’)" part. psql won't accept the literals in the IN clause. Is this normal? What could fix this?

I've tried just doing:
(
after logging in to psql connected to a specific database)

select * from pg_class where relkind IN IN (‘r’, ‘v’, ‘S’);

and that doesn't work either.

Dennis Gearon

Signature Warning
----------------
EARTH has a Right To Life,
otherwise we all die.

Read 'Hot, Flat, and Crowded'
Laugh at http://www.yert.com/film.php

#2Thomas Kellerer
spam_eater@gmx.net
In reply to: Dennis Gearon (#1)
Re: use of IN() with literals

Dennis Gearon wrote on 18.05.2010 19:05:

select * from pg_class where relkind IN IN (‘r’, ‘v’, ‘S’);

^^ ^ ^

You repeated the keyword IN, and you are using the wrong quotes (unless this is a copy & paste problem of a broken email client)

select *
from pg_class
where relkind IN ('r', 'v', 'S');

should work

#3David W Noon
dwnoon@ntlworld.com
In reply to: Dennis Gearon (#1)
Re: use of IN() with literals

On Tue, 18 May 2010 10:05:49 -0700 (PDT), Dennis Gearon wrote about
[GENERAL] use of IN() with literals:

I'm trying to use the following script: (to give command line ability
to change grant on all tables in public in a database)

psql -t -c “SELECT ‘GRANT $1 ON public.’ || t.relname || ‘ TO $2;’
from pg_class t, pg_namespace s WHERE t.relkind IN (‘r’, ‘v’, ‘S’) AND
t.relnamespace=s.oid AND s.nspname=’public’;” $3 | psql $3

and it always fails at the "IN(‘r’, ‘v’, ‘S’)" part. psql won't accept
the literals in the IN clause. Is this normal? What could fix this?

It works for me, using 8.4.2.

I've tried just doing:
(
after logging in to psql connected to a specific database)

select * from pg_class where relkind IN IN (‘r’, ‘v’, ‘S’);

You have the word "IN" twice.
--
Regards,

Dave [RLU #314465]
======================================================================
dwnoon@ntlworld.com (David W Noon)
======================================================================

#4Dennis Gearon
gearond@sbcglobal.net
In reply to: David W Noon (#3)
Re: use of IN() with literals

Yep bad scraping from one site to another. Probably encoding.

Thanks for telling me what (should) have been obvious about the two INs. The gobbledy gook was bad encoding between the two web pages.

select
Dennis Gearon

Signature Warning
----------------
EARTH has a Right To Life,
  otherwise we all die.

Read 'Hot, Flat, and Crowded'
Laugh at http://www.yert.com/film.php