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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

psql \echo strangeness with :variables


  • From: Jerry Sievers <jerry(at)jerrysievers(dot)com>
  • To: pgsql-general(at)postgresql(dot)org
  • Subject: psql \echo strangeness with :variables
  • Date: 24 May 2006 16:57:39 -0400
  • Message-id: <m3ejyjp2d8(dot)fsf(at)prod01(dot)jerrysievers(dot)com>

Hello.  Today I used a shell call in psql to save the runtime date in
a psql variable and use this to dynamically create tables with date
encoded in table name.

For some reason however, the psql \echo command can't  expand the date
though it does expand in the calls to the backend.

See example below;

jsievers(at)jsievers#
= \set date `date '+%Y%m%d'`

jsievers(at)jsievers#
= \echo :date
20060524

jsievers(at)jsievers#
= \echo foo_:date
foo_:date   <--  Was expecting this to expand... see below

jsievers(at)jsievers#
= create table foo_:date();
CREATE TABLE

jsievers(at)jsievers#
= \dt
            List of relations
 Schema |     Name     | Type  |  Owner   
--------+--------------+-------+----------
 public | foo_20060524 | table | jsievers
(1 row)

Seems there's a bit of asymmetry in the way psql evaluates the
:variables.

FYI

-- 
-------------------------------------------------------------------------------
Jerry Sievers   305 854-3001 (home)     WWW ECommerce Consultant
                305 321-1144 (mobile	http://www.JerrySievers.com/



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group