Re: Please help

From: <operationsengineer1(at)yahoo(dot)com>
To: Kumar S <ps_postgres(at)yahoo(dot)com>, Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Please help
Date: 2005-03-01 18:41:33
Message-ID: 20050301184134.95408.qmail@web52402.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

kumar, if you know the key is always the highest id
(in this case 5) then you can sort in descending order
and limit your result to one entry - which, by
definition, will be the largest "id" (equal to 5 in
this case).

something like...

$id = "SELECT cust_id from customer where
ustomer_name ='$cust' order by cust_id desc limit 1";

except applied to your case. pay special attention
to...

"order by cust_id desc limit 1"

Vishal showed me this example to solve another problem
and it may well solve yours, too.

--- Kumar S <ps_postgres(at)yahoo(dot)com> wrote:

> Hi Sean,
> I tried a SELECT statement in INSERT Statement.
>
>
>
> INSERT into xx(aa,aa,my_FK) values(bb,bb,
>
> (SELECT my_fk
> from my_chip_table
> where chip_description ~'U133A'
> )
> );
>
> The problem with this procedure is:
>
> genechip_id
> -------------
> 4
> 5
> (2 rows)
>
>
> I am getting two chips:
>
> 4 | Human Genome U133A 2.0 Array |Homo sapiens
> 5 | Human Genome U133A Array | Homo sapiens
>
> U133A has also a Ver.2.
>
> Any suggestions?
>
> Thanks
> Kumar
>
>
>
>
> --- Sean Davis <sdavis2(at)mail(dot)nih(dot)gov> wrote:
>
> >
> > On Mar 1, 2005, at 12:32 PM, Kumar S wrote:
> >
> > > Hello all,
> > >
> > >
> > > I have a table and it has is like this:
> > > exp_id
> > > exp_name
> > > exp_type
> > > exp_desc
> > > exp_pmid
> > > exp_paper
> > > exp_author
> > > genechip_id
> > > exp_rawdata_link
> > > con_id
> > > Indexes:
> > > "experiment_pkey" primary key, btree
> (exp_id)
> > > Foreign-key constraints:
> > > "$1" FOREIGN KEY (genechip_id) REFERENCES
> > > genechip_array(genechip_id)
> > > "$2" FOREIGN KEY (con_id) REFERENCES
> > > contacts(con_id)
> > >
> > >
> > > Based on the data I have information that should
> > fill
> > > in this column U133A.
> > >
> > > What I have in the genechip_array table is
> > >
> > > genechip_id | fc_genechip_array
> |gc_spec
> > > --+----------------------+------------------
> > >
> > > 5 | Human Genome U133A Array | Homo sapiens
> > >
> > >
> > > Now how can I bring in the foreign key 5 to my
> > > previous table. All I have is U133A.
> > >
> > > Could any one help me in this.
> > >
> >
> > Postgresql doesn't do this automatically. A
> foreign
> > key only functions
> > as a link between tables after it is formed. You
> > must supply the link
> > in the first place by a lookup in the foreign
> table
> > either in the
> > client or as part of a function to load the data.
> > You aren't going to
> > have many genechip_ids, so you could easily just
> > append a column full
> > of "5" to the incoming data for each of those
> tables
> > if you want a
> > quick and easy solution.
> >
> > Sean
> >
> >
> > ---------------------------(end of
> > broadcast)---------------------------
> > TIP 2: you can get off all lists at once with the
> > unregister command
> > (send "unregister YourEmailAddressHere" to
> > majordomo(at)postgresql(dot)org)
> >
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - Find what you need with new enhanced
> search.
> http://info.mail.yahoo.com/mail_250
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to
> majordomo(at)postgresql(dot)org
>


__________________________________
Do you Yahoo!?
Yahoo! Mail - 250MB free storage. Do more. Manage less.
http://info.mail.yahoo.com/mail_250

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Sean Davis 2005-03-01 18:57:59 Re: Please help
Previous Message Tom Lane 2005-03-01 18:27:00 Re: Anyarray with mixed data types inside of a PL/PLSQL function parameter