pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
[SQL] CREATE TABLE (fwd ): again!
3+ messages / 3 participants
[nested] [flat]

* [SQL] CREATE TABLE (fwd ): again!
@ 1999-03-05 20:07 Ingrith Andrea Correa Vargas <i-correa@uniandes.edu.co>
  1999-03-05 21:15 ` Re: [SQL] CREATE TABLE (fwd ): again! Gene Selkov Jr. <selkovjr@xnet.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Ingrith Andrea Correa Vargas @ 1999-03-05 20:07 UTC (permalink / raw)
  To: pgsql-sql


---------- Forwarded message ----------
Date: Fri, 5 Mar 1999 15:06:28 -0500 (GMT+5)
From: Ingrith Andrea Correa Vargas <i-correa@uniandes.edu.co>
Subject: [SQL] CREATE TABLE (fwd ): again!


Hello all!

I beleive that somebody knows how to answer my question...please!!


Make me a favor, please: Im going to send to you what I did, can you see
that and tell me what could be bad?!.

The example is:


---------------------------------------------------------
CREATE TABLE emp (code INT4
  , name VARCHAR(20)
  , salary INT4
  , 2salary INT4 default double_salary(emp)
);

CREATE FUNCTION double_salary(emp) RETURNS INT4
AS 'SELECT $1.salay * 2 AS result' LANGUAGE 'sql'
;

ERROR:  parser: syntax error at or near ")"
---------------------------------------------------------

Function double_salary receives an 'emp' , as you see, and there is the
error, because if I change parameter 'emp' by a number, the error doesn't
appear.

How can I do?!

The origin of this question is that I want to know if a subclass inherits
all atributtes from the parent, included functions like double_salary in
my example.

Can you help me?!...


Thank you in advance.


// Ingrith :)






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

* Re: [SQL] CREATE TABLE (fwd ): again!
  1999-03-05 20:07 [SQL] CREATE TABLE (fwd ): again! Ingrith Andrea Correa Vargas <i-correa@uniandes.edu.co>
@ 1999-03-05 21:15 ` Gene Selkov Jr. <selkovjr@xnet.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Gene Selkov Jr. @ 1999-03-05 21:15 UTC (permalink / raw)
  To: Ingrith Andrea Correa Vargas <i-correa@uniandes.edu.co>; pgsql-sql

> Hello all!
> 
> I beleive that somebody knows how to answer my question...please!!

I think the reason you are not getting an (immediate) answer from the
list is that you appear to be exploring the stuff that has been pretty
much abandoned since postgres95, not because we are insensitive barbarians
with disrespect for newbies ;)

There are still some areas in postgres about which people just can't
speak with confidence.

> Make me a favor, please: Im going to send to you what I did, can you see
> that and tell me what could be bad?!.
> 
> The example is:
> 
> 
> ---------------------------------------------------------
> CREATE TABLE emp (code INT4
>   , name VARCHAR(20)
>   , salary INT4
>   , 2salary INT4 default double_salary(emp)
> );
> 
> CREATE FUNCTION double_salary(emp) RETURNS INT4
> AS 'SELECT $1.salay * 2 AS result' LANGUAGE 'sql'
> ;

As I understood your intent, you want the value of 2salary (BTW,
2salary would not be a valid identifier) to be twice the value of the
other attribute by default. The problem here is that $1.salay (watch
typos!) refers to the whole salary column, not to its value in the row
you are inserting. There is no way to let the function know what the
'current' row is.

If I where you, I would set a rule or a trigger, or simply run a query like this:

UPDATE emp SET salary2 = salary * 2 FROM emp WHERE salary2 ISNULL;

> Function double_salary receives an 'emp' , as you see, and there is the
> error, because if I change parameter 'emp' by a number, the error doesn't
> appear.

The current syntax does not obviously allow identifiers here. There is
probably no use for identifiers in this context, anyway. It is
normally used with constants, such as:

DEFAULT nextval('default_seq'));

> The origin of this question is that I want to know if a subclass inherits
> all attributes from the parent, included functions like double_salary in
> my example.

Attributes or functions? Functions do not belong within classes and
therefore cannot be inherited. You should view functions as
stand-alone entities. Only attributes are inherited, and it is hard to
say to what degree the inheritance mechanism remained functional in
the course of development. Since no one seems to use it, your best
source of information (other than the postgres source code and
original developers themselves) would be the files in src/test/regress


--Gene



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

* Re: [SQL] CREATE TABLE (fwd ): again!
@ 1999-03-06 16:54 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 1999-03-06 16:54 UTC (permalink / raw)
  To: pgsql-sql@hub.org

"Gene Selkov Jr." <selkovjr@xnet.com> writes:
> ... Only attributes are inherited, and it is hard to
> say to what degree the inheritance mechanism remained functional in
> the course of development. Since no one seems to use it,

I use inheritance of table attributes constantly --- it seems to work
fine.  Someone else recently contributed patches for pg_dump that made
it do the right thing with inherited constraints, so I'm not the only
developer who uses inheritance...

			regards, tom lane



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


end of thread, other threads:[~1999-03-06 16:54 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-03-05 20:07 [SQL] CREATE TABLE (fwd ): again! Ingrith Andrea Correa Vargas <i-correa@uniandes.edu.co>
1999-03-05 21:15 ` Gene Selkov Jr. <selkovjr@xnet.com>
1999-03-06 16:54 Re: [SQL] CREATE TABLE (fwd ): again! Tom Lane <tgl@sss.pgh.pa.us>

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