Using psql variables in scripts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

 

Thanks,
Corey Horton


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux