Thread: New FAQ items

New FAQ items

From
Bruce Momjian
Date:
Here are two new FAQ items.  They are on the web site, along with an
expanded TODO list.

---------------------------------------------------------------------------


4.22) How do I create a column that will default to the current time?

The tempation is to do:

        create table test (x int, modtime timestamp default 'now');

but this makes the column default to the time of table creation, not the
time of row insertion.
Instead do:

        CREATE TABLE test (x int, modtime timestamp default now() );

The calling of the function now() prevents the default value from being
computed at table creation time, and delays it until insertion time. We
believe this will not be a problem in post-6.5.* releases.

4.23) Why are my subqueries using IN so slow?

Currently, we join subqueries to outer queries by sequential scanning
the result of the subquery for each row of the outer query. A workaround
is to replace IN with EXISTS. For example, change:


        SELECT *
        FROM tab
        WHERE col1 IN (SELECT col2 FROM TAB2)

to:


        SELECT *
        FROM tab
        WHERE EXISTS (SELECT col2 FROM TAB2 WHERE col1 = col2)

We hope to fix this limitation in a future release.


--
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026