Thread: Some Questions

Some Questions

From
Ludwig Lim
Date:
Hi:
   I would like to ask the following questions:
a) Are foreign key constraint triggers guaranteed to
execute first before any ordinary "BEFORE
INSERT/UPDATE/DELETE" trigger is executed? (This is
assuming that the foreign keys are declared as "NOT
DEFERRABLE")

b) Is "varchar" (without upper limit) the same as
"text"?   I do notice that when I create a view :  create view v_test as (select 'test'::varchar(10)
union select 'test1'::varchar(10));
  a "\d v_test" on the psql prompt would always say
the only only column the view is of type "character
varying". Does a union of a varchar(n) column and a
another varchar(n) column would automatically cast it
to "character varying" (w/o upper limit) even if the
upper limit of the 2 varchar columns are the same?

thanks in advance,
ludwig lim





__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com


Re: Some Questions

From
Stephan Szabo
Date:
On Thu, 12 Jun 2003, Ludwig Lim wrote:

>     I would like to ask the following questions:
> a) Are foreign key constraint triggers guaranteed to
> execute first before any ordinary "BEFORE
> INSERT/UPDATE/DELETE" trigger is executed? (This is
> assuming that the foreign keys are declared as "NOT
> DEFERRABLE")

No.  Before triggers are going to get run before the action
occurs, the constraint triggers are in general going to run
after the action occurs (before triggers might change
information about the new row). It'll currently run in
the after triggers where it false in name order so you
can place after triggers before or after the constraint
trigger.

> b) Is "varchar" (without upper limit) the same as
> "text"?

Not quite, but it's close (there might still be issues
with mismatching set returning function returns and probably
some other similar cases).

>    I do notice that when I create a view :
>    create view v_test as (select 'test'::varchar(10)
> union select 'test1'::varchar(10));
>
>    a "\d v_test" on the psql prompt would always say
> the only only column the view is of type "character
> varying". Does a union of a varchar(n) column and a
> another varchar(n) column would automatically cast it
> to "character varying" (w/o upper limit) even if the
> upper limit of the 2 varchar columns are the same?

As a side note, in 7.4, create view reports the type as
character varying and a create table as reports it as
character varying(10).