pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: Inserting data in composite types!
4+ messages / 4 participants
[nested] [flat]

* Re: Inserting data in composite types!
@ 2006-11-13 12:28  Markus Schiltknecht <markus@bluegap.ch>
  parent: Rodrigo Sakai <rodrigo.sakai@zanthus.com.br>
  2 siblings, 0 replies; 4+ messages in thread

From: Markus Schiltknecht @ 2006-11-13 12:28 UTC (permalink / raw)
  To: rodrigo.sakai@zanthus.com.br; +Cc: pgsql-sql

Hi,

Rodrigo Sakai wrote:
> How can I insert a single row in this table???

INSERT INTO employee (emp_salary)
   VALUES ((1000.00, '(2006/10/10, 2006/12/10)'));


BTW: are you sure you don't want to use foreign keys instead? Something 
like:

CREATE TABLE salaries (
   id SERIAL PRIMARY KEY,
   salary numeric(10,2) NOT NULL,
   t_date t_time NOT NULL
);

CREATE TABLE employee (
   employee_id SERIAL PRIMARY KEY,
   name TEXT NOT NULL,
   salary INT NOT NULL REFERENCES salaries(id)
);

Regards

Markus



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

* Inserting data in composite types!
@ 2006-11-13 12:37  Rodrigo Sakai <rodrigo.sakai@zanthus.com.br>
  0 siblings, 3 replies; 4+ messages in thread

From: Rodrigo Sakai @ 2006-11-13 12:37 UTC (permalink / raw)
  To: pgsql-sql

  Hi, I have a question about how to insert data in composite types!

 

  Imagine the exemple:

 

CREATE TYPE t_time AS (

  a date,

  b date

);

 

CREATE TABLE salary (

   salary numeric(10,2),

   t_date t_time

);

 

I know that if I want to insert data in the table SALARY I just have to do
like:

 

  INSERT INTO salary VALUES (1000.00, '(2006/10/10, 2006/12/10)');

 

But if I have another table:

 

CREATE TABLE employee (

  employee_id int,

  name varchar(30),

  emp_salary salary

)

 

How can I insert a single row in this table???

 

Thanks in advamce!

 

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

* Re: Inserting data in composite types!
@ 2006-11-13 12:46  Shane Ambler <pgsql@007Marketing.com>
  parent: Rodrigo Sakai <rodrigo.sakai@zanthus.com.br>
  2 siblings, 0 replies; 4+ messages in thread

From: Shane Ambler @ 2006-11-13 12:46 UTC (permalink / raw)
  To: rodrigo.sakai@zanthus.com.br; +Cc: pgsql-sql

Rodrigo Sakai wrote:
>   Hi, I have a question about how to insert data in composite types!
> 
>  
> 
>   Imagine the exemple:
> 
>  
> 
> CREATE TYPE t_time AS (
> 
>   a date,
> 
>   b date
> 
> );
> 
>  
> 
> CREATE TABLE salary (
> 
>    salary numeric(10,2),
> 
>    t_date t_time
> 
> );
> 
>  
> 
> I know that if I want to insert data in the table SALARY I just have to do
> like:
> 
>  
> 
>   INSERT INTO salary VALUES (1000.00, '(2006/10/10, 2006/12/10)');
> 
>  
> 
> But if I have another table:
> 
>  
> 
> CREATE TABLE employee (
> 
>   employee_id int,
> 
>   name varchar(30),
> 
>   emp_salary salary
> 
> )

I am thinking that with the salary type here you are thinking of your 
salary table defined above?
If so and you want them in a separate table to record salary histories 
then you want to create a foreign key to link them.

You would end up with -

CREATE TABLE employee (

   employee_id int PRIMARY KEY,

   name varchar(30)

);

CREATE TABLE salary (

    emp_id int REFERENCES employee(employee_id) ON DELETE CASCADE,

    salary numeric(10,2),

    t_date t_time

);

then -
INSERT INTO salary VALUES (1, 1000.00, '(2006/10/10, 2006/12/10)');


Otherwise you will want to change the CREATE TABLE salary... to CREATE 
TYPE salary...

Probably as
CREATE TYPE salary AS(
    salary numeric(10,2),
    a date,
    b date
);

You can then
INSERT INTO employee VALUES
(1,'Hard Worker','(1000.00, 2006/10/10, 2006/12/10)');


-- 

Shane Ambler
pgSQL@007Marketing.com

Get Sheeky @ http://Sheeky.Biz



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

* Re: Inserting data in composite types!
@ 2006-11-13 14:09  imad <immaad@gmail.com>
  parent: Rodrigo Sakai <rodrigo.sakai@zanthus.com.br>
  2 siblings, 0 replies; 4+ messages in thread

From: imad @ 2006-11-13 14:09 UTC (permalink / raw)
  To: rodrigo.sakai@zanthus.com.br; +Cc: pgsql-sql

I am able to do this thing with the following query:

insert into employee (a, name, s) values(1, 'emp name', ((1,
'(01/01/2000, 01/01/2000)')));


--Imad
www.EnterpriseDB.com




On 11/13/06, Rodrigo Sakai <rodrigo.sakai@zanthus.com.br> wrote:
>
>
>
>
>   Hi, I have a question about how to insert data in composite types!
>
>
>
>   Imagine the exemple:
>
>
>
> CREATE TYPE t_time AS (
>
>   a date,
>
>   b date
>
> );
>
>
>
> CREATE TABLE salary (
>
>    salary numeric(10,2),
>
>    t_date t_time
>
> );
>
>
>
> I know that if I want to insert data in the table SALARY I just have to do
> like:
>
>
>
>   INSERT INTO salary VALUES (1000.00, '(2006/10/10, 2006/12/10)');
>
>
>
> But if I have another table:
>
>
>
> CREATE TABLE employee (
>
>   employee_id int,
>
>   name varchar(30),
>
>   emp_salary salary
>
> )
>
>
>
> How can I insert a single row in this table???
>
>
>
> Thanks in advamce!
>
>



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


end of thread, other threads:[~2006-11-13 14:09 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-11-13 12:37 Inserting data in composite types! Rodrigo Sakai <rodrigo.sakai@zanthus.com.br>
2006-11-13 12:28 ` Markus Schiltknecht <markus@bluegap.ch>
2006-11-13 12:46 ` Shane Ambler <pgsql@007Marketing.com>
2006-11-13 14:09 ` imad <immaad@gmail.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