Re: psql variable interpolation with subsequent underscore

From: Bosco Rama <postgres(at)boscorama(dot)com>
To: Tim Kane <tim(dot)kane(at)gmail(dot)com>, pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: Re: psql variable interpolation with subsequent underscore
Date: 2013-11-08 17:57:03
Message-ID: 527D25EF.60609@boscorama.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 11/08/13 09:30, Tim Kane wrote:
>
> Remi, to answer your question - this is being called as part of a shell
> script.

In that case your options expand greatly...

For example:
tbl_name="YYYYMM"

psql -c "alter table my_table rename to my_table_${tbl_name}_raw;"

or for more complex stuff:
tbl_name="YYYYMM"

psql -f- <<EOF
alter table my_table rename to my_table_${tbl_name}_raw;
... <other DML/DDL>
EOF

Or even:
(
<bunch of commands generating SQL DML/DDL>

) | psql -f-

Or ...

The sky's the limit once you remove the restriction of working 100%
*within* psql itself.

HTH

Bosco.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John R Pierce 2013-11-08 18:00:31 Re: psql variable interpolation with subsequent underscore
Previous Message Tim Kane 2013-11-08 17:30:30 Re: psql variable interpolation with subsequent underscore