pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
\set
5+ messages / 3 participants
[nested] [flat]

* \set
@ 2004-05-11 23:07 Jie Liang <jie@stbernard.com>
  2004-05-12 10:13 ` Re: [SQL] \set Christian Kratzer <ck@cksoft.de>
  0 siblings, 1 reply; 5+ messages in thread

From: Jie Liang @ 2004-05-11 23:07 UTC (permalink / raw)
  To: pgsql-admin@postgresql.org; +Cc: pgsql-sql

Hi,
How to use an internal variable?
Original question was how to set a variable in postgresql?
If I want to set a variable like start_date='2004-05-10';
How could I use it in my SQL statement?
E.g.

Db> set start_date '2004-05-10'
Db> select start_date as 'start date';

It's not executable!


Thanks.

Jie Liang



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [SQL] \set
  2004-05-11 23:07 \set Jie Liang <jie@stbernard.com>
@ 2004-05-12 10:13 ` Christian Kratzer <ck@cksoft.de>
  0 siblings, 0 replies; 5+ messages in thread

From: Christian Kratzer @ 2004-05-12 10:13 UTC (permalink / raw)
  To: Jie Liang <jie@stbernard.com>; +Cc: pgsql-admin@postgresql.org; pgsql-sql

Hi,

On Tue, 11 May 2004, Jie Liang wrote:

> Hi,
> How to use an internal variable?
> Original question was how to set a variable in postgresql?
> If I want to set a variable like start_date='2004-05-10';
> How could I use it in my SQL statement?
> E.g.
>
> Db> set start_date '2004-05-10'
> Db> select start_date as 'start date';
>
> It's not executable!

from doc/postgresql/html/sql-set.html

--snipp--
 	Synopsis

 	SET [ SESSION | LOCAL ] name { TO | = } { value | 'value' | DEFAULT }
 	SET [ SESSION | LOCAL ] TIME ZONE { timezone | LOCAL | DEFAULT }

 	...
 	...
 	...

 	name

 	    Name of a settable run-time parameter.
 	    Available parameters are documented in Section 16.4 and below. 
--snipp--

that is you can only use SET to change specific predefined parameters.
It does not say you could use SET to store other data local to the database
session.

As far as I know there are no session local variables in postgresql.
I could use something like this myself. The only workaround I know of 
to have data local to a session is to create a temporary table for the data.

There are local variables in plpgsql if you are just looking for local
variables.

Greetings
Christian

-- 
Christian Kratzer                       ck@cksoft.de
CK Software GmbH                        http://www.cksoft.de/
Phone: +49 7452 889 135                 Fax: +49 7452 889 136



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [SQL] \set
@ 2004-05-12 21:59 Jie Liang <jie@stbernard.com>
  2004-05-12 23:05 ` Re: [SQL] \set Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 5+ messages in thread

From: Jie Liang @ 2004-05-12 21:59 UTC (permalink / raw)
  To: Christian Kratzer <ck@cksoft.de>; +Cc: pgsql-admin@postgresql.org; pgsql-sql

I am not talking about SET, I am talking about \set command.
Yes, I understand, plpgsql can work around it, but I think postgresql
should have a simple way to do it.
E.g.
Db>\set AAA 'whatever'
Db>\set
You will see AAA associate with 'whatever', it's an internal variable,
but how could I use it in my SQL query?


Thanks anyway.


Jie Liang

-----Original Message-----
From: Christian Kratzer [mailto:ck@cksoft.de] 
Sent: Wednesday, May 12, 2004 3:13 AM
To: Jie Liang
Cc: pgsql-admin@postgresql.org; pgsql-sql@postgresql.org
Subject: Re: [SQL] \set


Hi,

On Tue, 11 May 2004, Jie Liang wrote:

> Hi,
> How to use an internal variable?
> Original question was how to set a variable in postgresql?
> If I want to set a variable like start_date='2004-05-10';
> How could I use it in my SQL statement?
> E.g.
>
> Db> set start_date '2004-05-10'
> Db> select start_date as 'start date';
>
> It's not executable!

from doc/postgresql/html/sql-set.html

--snipp--
 	Synopsis

 	SET [ SESSION | LOCAL ] name { TO | = } { value | 'value' |
DEFAULT }
 	SET [ SESSION | LOCAL ] TIME ZONE { timezone | LOCAL | DEFAULT }

 	...
 	...
 	...

 	name

 	    Name of a settable run-time parameter.
 	    Available parameters are documented in Section 16.4 and
below. 
--snipp--

that is you can only use SET to change specific predefined parameters.
It does not say you could use SET to store other data local to the
database session.

As far as I know there are no session local variables in postgresql. I
could use something like this myself. The only workaround I know of 
to have data local to a session is to create a temporary table for the
data.

There are local variables in plpgsql if you are just looking for local
variables.

Greetings
Christian

-- 
Christian Kratzer                       ck@cksoft.de
CK Software GmbH                        http://www.cksoft.de/
Phone: +49 7452 889 135                 Fax: +49 7452 889 136



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [SQL] \set
  2004-05-12 21:59 Re: [SQL] \set Jie Liang <jie@stbernard.com>
@ 2004-05-12 23:05 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2004-05-12 23:05 UTC (permalink / raw)
  To: Jie Liang <jie@stbernard.com>; +Cc: Christian Kratzer <ck@cksoft.de>; pgsql-admin@postgresql.org; pgsql-sql

"Jie Liang" <jie@stbernard.com> writes:
> You will see AAA associate with 'whatever', it's an internal variable,
> but how could I use it in my SQL query?

regression=# \set AAA 'whatever'
regression=# select :AAA;
ERROR:  column "whatever" does not exist
regression=# \set AAA '\'whatever\''
regression=# select :AAA;
 ?column?
----------
 whatever
(1 row)
 
			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [SQL] \set
@ 2004-05-12 23:40 Jie Liang <jie@stbernard.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Jie Liang @ 2004-05-12 23:40 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Christian Kratzer <ck@cksoft.de>; pgsql-admin@postgresql.org; pgsql-sql

Thank you, Tom.

Jie

-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us] 
Sent: Wednesday, May 12, 2004 4:06 PM
To: Jie Liang
Cc: Christian Kratzer; pgsql-admin@postgresql.org;
pgsql-sql@postgresql.org
Subject: Re: [ADMIN] [SQL] \set 


"Jie Liang" <jie@stbernard.com> writes:
> You will see AAA associate with 'whatever', it's an internal variable,

> but how could I use it in my SQL query?

regression=# \set AAA 'whatever'
regression=# select :AAA;
ERROR:  column "whatever" does not exist
regression=# \set AAA '\'whatever\''
regression=# select :AAA;
 ?column?
----------
 whatever
(1 row)
 
			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2004-05-12 23:40 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-05-11 23:07 \set Jie Liang <jie@stbernard.com>
2004-05-12 10:13 ` Christian Kratzer <ck@cksoft.de>
2004-05-12 21:59 Re: [SQL] \set Jie Liang <jie@stbernard.com>
2004-05-12 23:05 ` Tom Lane <tgl@sss.pgh.pa.us>
2004-05-12 23:40 Re: [SQL] \set Jie Liang <jie@stbernard.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox