Skip site navigation (1) Skip section navigation (2)

Using psql variables in scripts

From: Corey Horton <Corey_Horton(at)messageone(dot)com>
To: <pgsql-admin(at)postgresql(dot)org>
Subject: Using psql variables in scripts
Date: 2008-05-30 17:39:14
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-admin
Would like to use variables in combination with files for common psql
queries, and am using PG 8.1.4.


For example

\set table_name pg_class


select * from pg_tables where tablename = ':table_name';


This returns no rows, even though the customer table exists.  It appears
to be search for a table called ":table_name".


I can get this to work by doing the following:


\set table_name '\'pg_class\''

select * from pg_tables where tablename = :table_name;


 schemaname | tablename | tableowner | tablespace | hasindexes |
hasrules | hastriggers


 pg_catalog | pg_class  | postgres   |            | t          | f
| f



Is there any way to do use variables within quotes?


Corey Horton

pgsql-admin by date

Next:From: Ivo RossacherDate: 2008-05-30 17:46:32
Subject: Re: Migration from ASCII to UTF8
Previous:From: Igor NeymanDate: 2008-05-30 16:32:29
Subject: dobc install error on Windows

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group