subquery with more than one column

Lists: pgsql-novice
From: Raimon Fernandez <coder(at)montx(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: oid or without oid ...
Date: 2007-05-22 07:30:34
Message-ID: DC4D44E8-0E37-44C6-B578-37A02D3DDADD@montx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

Hello again,

In my previous databases development, I've been using always a unique
longint number for identifying each record.

In PostgreSQL I can see that it has the oid, he can do it for you.

Also I see that is an optional parameter, and after surfing the web,
I could find some people that say never use them, an another ones
that you can use it ...

Any extra advice would be perfectly before creating the database, if
it's better for now and future to use oid or simply create an id
field as a serial or something similar.

thanks,

raimon fernandez


From: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
To: pgsql-novice(at)postgresql(dot)org
Cc: Raimon Fernandez <coder(at)montx(dot)com>
Subject: Re: oid or without oid ...
Date: 2007-05-22 09:57:09
Message-ID: 200705220557.10023.sdavis2@mail.nih.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

On Tuesday 22 May 2007 03:30, Raimon Fernandez wrote:
> Hello again,
>
>
> In my previous databases development, I've been using always a unique
> longint number for identifying each record.
>
> In PostgreSQL I can see that it has the oid, he can do it for you.
>
> Also I see that is an optional parameter, and after surfing the web,
> I could find some people that say never use them, an another ones
> that you can use it ...
>
> Any extra advice would be perfectly before creating the database, if
> it's better for now and future to use oid or simply create an id
> field as a serial or something similar.

In general, the recommendation is not to use OIDs. Use serial columns (or
some other primary key) instead.

Sean


From: Raimon Fernandez <coder(at)montx(dot)com>
To: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: oid or without oid ...
Date: 2007-05-22 10:05:46
Message-ID: 42FD0AF0-D6FB-492A-A28B-616DD01CD661@montx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

I'm trying with this approach:

create table public.articles( "id" int4 not null default nextval
('articles_id_seq'::regclass) , "referencia" varchar not null
)
WITHOUT OIDS;
ALTER table "public"."articles" OWNER TO "postgres";
ALTER table "public"."articles" SET WITHOUT CLUSTER;
alter table "public"."articles" add primary key(id);

and after some test, it works ...

thanks for the advice!

regards,

raimon

On 22/05/2007, at 11:57, Sean Davis wrote:

> On Tuesday 22 May 2007 03:30, Raimon Fernandez wrote:
>> Hello again,
>>
>>
>> In my previous databases development, I've been using always a unique
>> longint number for identifying each record.
>>
>> In PostgreSQL I can see that it has the oid, he can do it for you.
>>
>> Also I see that is an optional parameter, and after surfing the web,
>> I could find some people that say never use them, an another ones
>> that you can use it ...
>>
>> Any extra advice would be perfectly before creating the database, if
>> it's better for now and future to use oid or simply create an id
>> field as a serial or something similar.
>
> In general, the recommendation is not to use OIDs. Use serial
> columns (or
> some other primary key) instead.
>
> Sean
>


From: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
To: Raimon Fernandez <coder(at)montx(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: oid or without oid ...
Date: 2007-05-22 10:08:41
Message-ID: 200705220608.41284.sdavis2@mail.nih.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

On Tuesday 22 May 2007 06:05, Raimon Fernandez wrote:
> I'm trying with this approach:
>
> create table public.articles( "id" int4 not null default nextval
> ('articles_id_seq'::regclass) , "referencia" varchar not null
> )
> WITHOUT OIDS;
> ALTER table "public"."articles" OWNER TO "postgres";
> ALTER table "public"."articles" SET WITHOUT CLUSTER;
> alter table "public"."articles" add primary key(id);

And keep in mind that you can use:

id serial

as a shorthand.

Sean


From: Raimon Fernandez <coder(at)montx(dot)com>
To: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: oid or without oid ...
Date: 2007-05-22 10:17:27
Message-ID: 46C073A8-2524-4CA2-A780-B5C000EA7118@montx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

you mean this:

create table public.test(id serial, ref varchar);

I was using Navicat PostgreSQL, a GUI that does lot of things, I'll
try with the command line ...

thanks !

rai

On 22/05/2007, at 12:08, Sean Davis wrote:

> On Tuesday 22 May 2007 06:05, Raimon Fernandez wrote:
>> I'm trying with this approach:
>>
>> create table public.articles( "id" int4 not null default nextval
>> ('articles_id_seq'::regclass) , "referencia" varchar not null
>> )
>> WITHOUT OIDS;
>> ALTER table "public"."articles" OWNER TO "postgres";
>> ALTER table "public"."articles" SET WITHOUT CLUSTER;
>> alter table "public"."articles" add primary key(id);
>
> And keep in mind that you can use:
>
> id serial
>
> as a shorthand.
>
> Sean
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>


From: Raimon Fernandez <coder(at)montx(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: subquery with more than one column
Date: 2007-07-05 18:34:25
Message-ID: 6506B613-A727-4BA1-BC59-6B48E5666A7D@montx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

Hi,

It's not possible to return in a subquery more than one column ?

SELECT id_intern, (SELECT referencia, descripcio FROM articles WHERE
id_intern = product_blister.id_product_added) FROM product_blister
WHERE id_product_source = '8';

so, I would have to add a new subquery for each column I want to
retrieve ?

like this:

SELECT id_intern, (SELECT referencia FROM articles WHERE id_intern =
product_blister.id_product_added),(SELECT descripcio FROM articles
WHERE id_intern = product_blister.id_product_added) FROM
product_blister WHERE id_product_source = '8';

all of them are from the same table ...

regards,

raimon fernandez


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Raimon Fernandez <coder(at)montx(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: subquery with more than one column
Date: 2007-07-05 19:30:33
Message-ID: 20860.1183663833@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

Raimon Fernandez <coder(at)montx(dot)com> writes:
> It's not possible to return in a subquery more than one column ?

Try it like this:

SELECT id_intern, (SELECT ROW(referencia, descripcio) FROM articles WHERE...

regards, tom lane


From: Raimon Fernandez <coder(at)montx(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: subquery with more than one column
Date: 2007-07-05 20:51:37
Message-ID: 989D18C1-AF52-4AFE-8581-2B988B457DA4@montx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

but I want as a separate columns, like a normal SELECT ...

this is what I get:

+---------------+
| row |
+---------------+
| (1,"ref rai") |
| (1,ref) |
+---------------+

thanks,

raimon

On 05/07/2007, at 21:30, Tom Lane wrote:

> Raimon Fernandez <coder(at)montx(dot)com> writes:
>> It's not possible to return in a subquery more than one column ?
>
> Try it like this:
>
> SELECT id_intern, (SELECT ROW(referencia, descripcio) FROM
> articles WHERE...
>
> regards, tom lane
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
>


From: Jon Sime <jsime(at)mediamatters(dot)org>
To: PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org>
Cc: Raimon Fernandez <coder(at)montx(dot)com>
Subject: Re: subquery with more than one column
Date: 2007-07-05 21:27:48
Message-ID: 468D6254.6060501@mediamatters.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

Raimon Fernandez wrote:
> [..moved top-post..]
> On 05/07/2007, at 21:30, Tom Lane wrote:
>
>> Raimon Fernandez <coder(at)montx(dot)com> writes:
>>> It's not possible to return in a subquery more than one column ?
>>
>> Try it like this:
>>
>> SELECT id_intern, (SELECT ROW(referencia, descripcio) FROM articles
>> WHERE...
>>
>> regards, tom lane
>>
> but I want as a separate columns, like a normal SELECT ...
>
>
> this is what I get:
>
> +---------------+
> | row |
> +---------------+
> | (1,"ref rai") |
> | (1,ref) |
> +---------------+
>
>
> thanks,
>
>
> raimon

Is there something about the nature of the data which prevents you from
using a JOIN between these two tables?

select pb.id_intern, a.referencia, a.descripcio
from product_blister pb
join articles a on (a.id_intern = pb.id_product_added)
where pb.id_product_source = '8';

(Or using a LEFT JOIN if not every record in product_blister is required
to have a corresponding record in articles, and you want those records
in product_blister to still be returned.)

My apologies if my assumption is incorrect.

-Jon

--
Senior Systems Developer
Media Matters for America
http://mediamatters.org/


From: Raimon Fernandez <coder(at)montx(dot)com>
To: PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: subquery with more than one column
Date: 2007-07-06 06:11:27
Message-ID: 88C55313-13B2-4F83-8D23-ECD1987D645B@montx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

great !!

that's what I was lookingfor ...

I think my brain was empty ...

:)

regards,

rai

On 05/07/2007, at 23:27, Jon Sime wrote:

> Raimon Fernandez wrote:
>> [..moved top-post..]
>> On 05/07/2007, at 21:30, Tom Lane wrote:
>>> Raimon Fernandez <coder(at)montx(dot)com> writes:
>>>> It's not possible to return in a subquery more than one column ?
>>>
>>> Try it like this:
>>>
>>> SELECT id_intern, (SELECT ROW(referencia, descripcio) FROM
>>> articles WHERE...
>>>
>>> regards, tom lane
>>>
> > but I want as a separate columns, like a normal SELECT ...
> >
> >
> > this is what I get:
> >
> > +---------------+
> > | row |
> > +---------------+
> > | (1,"ref rai") |
> > | (1,ref) |
> > +---------------+
> >
> >
> > thanks,
> >
> >
> > raimon
>
> Is there something about the nature of the data which prevents you
> from using a JOIN between these two tables?
>
> select pb.id_intern, a.referencia, a.descripcio
> from product_blister pb
> join articles a on (a.id_intern = pb.id_product_added)
> where pb.id_product_source = '8';
>
> (Or using a LEFT JOIN if not every record in product_blister is
> required to have a corresponding record in articles, and you want
> those records in product_blister to still be returned.)
>
> My apologies if my assumption is incorrect.
>
> -Jon
>
> --
> Senior Systems Developer
> Media Matters for America
> http://mediamatters.org/
>