Обсуждение: virtual (COMPUTED BY) columns?

Поиск
Список
Период
Сортировка

virtual (COMPUTED BY) columns?

От
Ron Johnson
Дата:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi.

These fields do not use any disk space, as the data in them is
derived on the fly.

For example:
CREATE TABLE T_EXAMPLE (
SOME_DATE DATE,
JDATE     COMPUTED BY EXTRACT(JULIAN FROM SOME_DATE)
);

A work-around is to create a function, and reference it in every
query, but storing them in the table definition is the "tidy",
low-maintenance way to do it.

Thanks
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFFvM59S9HxQb37XmcRAtFvAKC51YTKLLy+v+0TXMhGIyX2PmO2EQCfW8gy
yIn2EBd5gR82/Hf+j5CB+rQ=
=4Csd
-----END PGP SIGNATURE-----

Re: virtual (COMPUTED BY) columns?

От
"A. Kretschmer"
Дата:
am  Sun, dem 28.01.2007, um 10:25:33 -0600 mailte Ron Johnson folgendes:
> Hi.
>
> These fields do not use any disk space, as the data in them is
> derived on the fly.
>
> For example:
> CREATE TABLE T_EXAMPLE (
> SOME_DATE DATE,
> JDATE     COMPUTED BY EXTRACT(JULIAN FROM SOME_DATE)
> );
>
> A work-around is to create a function, and reference it in every
> query, but storing them in the table definition is the "tidy",
> low-maintenance way to do it.

Was this a question how to do this in PostgreSQL?

You can use a VIEW. Just create T_EXAMPLE ( SOME_DATE DATE );
and then

CREATE VIEW view_example AS SELECT some_date, EXTRACT(JULIAN FROM
some_date) AS julian_date FROM T_EXAMPLE;


Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

Re: virtual (COMPUTED BY) columns?

От
Ron Johnson
Дата:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 01/28/07 10:43, A. Kretschmer wrote:
> am  Sun, dem 28.01.2007, um 10:25:33 -0600 mailte Ron Johnson folgendes:
>> Hi.
>>
>> These fields do not use any disk space, as the data in them is
>> derived on the fly.
>>
>> For example:
>> CREATE TABLE T_EXAMPLE (
>> SOME_DATE DATE,
>> JDATE     COMPUTED BY EXTRACT(JULIAN FROM SOME_DATE)
>> );
>>
>> A work-around is to create a function, and reference it in every
>> query, but storing them in the table definition is the "tidy",
>> low-maintenance way to do it.
>
> Was this a question how to do this in PostgreSQL?
>
> You can use a VIEW. Just create T_EXAMPLE ( SOME_DATE DATE );
> and then
>
> CREATE VIEW view_example AS SELECT some_date, EXTRACT(JULIAN FROM
> some_date) AS julian_date FROM T_EXAMPLE;

Good point.

But then you have 2 bits of metadata, and yet one more object to
update when you add a column.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFFvNQjS9HxQb37XmcRArguAJ4y4e5rbpe4YoH+VNJXIW0XSrjRqQCfcLO4
78WYNnFb14wlI9hXJtwbSeM=
=KZkP
-----END PGP SIGNATURE-----