Re: [SQL] regarding join
given this. create table AA (id serial,name varchar(15)); create table BB (id serial,name varchar(15)); insert into AA (name) values ('1243f'); insert into AA (name) values ('asdfef'); insert into AA (name) values ('fdbsfd'); insert into AA (name) values ('btgrt'); insert into AA (name) values ('crregsewf'); insert into AA (name) values ('xedrgeef'); insert into BB (name) values ('243f'); insert into BB (name) values ('sdfef'); insert into BB (name) values ('dbsfd'); insert into BB (name) values ('tgrt'); insert into BB (name) values ('rregsewf'); insert into BB (name) values ('edrgeef'); you could try: (if you just need the one column "name") select name from AA union select name from BB order by name; a real nice way to go about this is: create table CC (id serial,name varchar(15)); create table AA() inherits(CC); create table BB() inherits(CC); insert into AA (name) values ('1243f'); insert into AA (name) values ('asdfef'); insert into AA (name) values ('fdbsfd'); insert into AA (name) values ('btgrt'); insert into AA (name) values ('crregsewf'); insert into AA (name) values ('xedrgeef'); insert into BB (name) values ('243f'); insert into BB (name) values ('sdfef'); insert into BB (name) values ('dbsfd'); insert into BB (name) values ('tgrt'); insert into BB (name) values ('rregsewf'); insert into BB (name) values ('edrgeef'); => select * from AA; id | name +--- 1 | 1243f 2 | asdfef 3 | fdbsfd 4 | btgrt 5 | crregsewf 6 | xedrgeef (6 rows) => select * from BB; id | name +-- 7 | 243f 8 | sdfef 9 | dbsfd 10 | tgrt 11 | rregsewf 12 | edrgeef (6 rows) => select * from CC order by name; id | name +--- 1 | 1243f 7 | 243f 2 | asdfef 4 | btgrt 5 | crregsewf 9 | dbsfd 12 | edrgeef 3 | fdbsfd 11 | rregsewf 8 | sdfef 10 | tgrt 6 | xedrgeef (12 rows) by best regards, Stefan -- email: [EMAIL PROTECTED] tel : +49 (0)6232-629542 länger klingeln lassen (Weiterleitung aktiv) fax : +49 (0)6232-629544 http://www.net-away.de Am Samstag, 25. März 2006 07:36 schrieb AKHILESH GUPTA: > hi all, > below I have created two tables in pgsql with field name as 'name' and 'id' > as their datatype 'varchar(15)' and 'integer'. > > One of the table is:-> > chemical=> select * from test1; > name | id > ---+ > akhil | 1 > b | 2 > c | 3 > d | 4 > e | 5 > f | 6 > (6 rows) > > Another table is:-> > chemical=> select * from test3; > name | id > --+ > ab | 1 > cd | 2 > ef | 3 > gh | 4 > (4 rows) > > i want the output as:-> > name | id > ---+ > akhil | 1 -from test1 table > ab | 1--from test2 table > b | 2-from test1 table > cd | 2--from test2 table > c | 3-from test1 table > ef | 3--from test2 table > d | 4-from test1 table > gh | 4--from test2 table > e | 5-from test1 table > f | 6-from test1 table > > i have tried all the joins but it makes different fields for different > tables. > is there any way out for this kind of output?? > (plz reply asap)urgent. > > THANKS IN ADVANCE > > -- > Thanks & Regards, > Akhilesh > S/W Trainee (EDP), > NUCHEM Pvt. Ltd., > Faridabad(Haryana) > GSM:-(+919891606064) > > "FAILURES CAN BE FORGIVEN BUT AIMING LOW IS A CRIME" ---(end of broadcast)--- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq
Re: [SQL] Index on nullable column
> > Is an index on a nullable column useful for retrieving rows having that > > column null? > > Nope, because IS NULL isn't an indexable operator. > > You can make an end-run around that with a partial index, eg > > create index fooi on foo(f1) where f1 is null > > This can be used to satisfy queries using "where f1 is null", but it's > not any good for any other purpose. > > If you often do "where f1 is null and something-about-f2", > you might get better mileage with > > create index fooi on foo(f2) where f1 is null > > but it's still a very specialized index. > Thanks Tom. I will use such an index even if it's very specialized; OLAP world is somewhat full of specialized index anyway... :-) -- Daniel ---(end of broadcast)--- TIP 6: explain analyze is your friend
Re: [SQL] Expressing a result set as an array (and vice versa)?
On Thu, 23 Mar 2006 11:44:32 -0800 Don Maier <[EMAIL PROTECTED]> threw this fish to the penguins: > Is it possible to construct an array from an appropriate select > expression that generates a result set of unknown cardinality? > To focus on the simple case: Is it possible to construct a one- > dimensional array from a select of a single column in a table with an > unknown number of rows? select array(select some_int_field from my_table where something); produces an array of integers. No user defined function is required. > Conversely, is it possible to construct a (single column) result set > from a select expression on a one-dimensional array with an unknown > number of elements? Not so easy without a custom function. > Thanks for any hints! > > Regards, > Don Maier > > > > ---(end of broadcast)--- > TIP 1: if posting/reading through Usenet, please send an appropriate >subscribe-nomail command to [EMAIL PROTECTED] so that your >message can get through to the mailing list cleanly > -- "Are the gods not just?" "Oh no, child. What would become of us if they were?" (CSL) ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings
Re: [SQL] Expressing a result set as an array (and vice versa)?
On Mar 25 10:11, george young wrote: > On Mar 23 11:44, Don Maier <[EMAIL PROTECTED]> wrote: > > Conversely, is it possible to construct a (single column) result set > > from a select expression on a one-dimensional array with an unknown > > number of elements? > > Not so easy without a custom function. But not that hard: test=> SELECT id, val FROM t_arr; id | val +--- 1 | {1,2,3} 2 | {4,5,6} 3 | {7,8,9} 4 | {10,11,12,13} (4 rows) -- -- First Way -- test=> SELECT id, val[s.i] test-> FROM t_arr test-> LEFT OUTER JOIN test-> (SELECT g.s test(> FROM generate_series(1, (SELECT max(array_upper(val, 1)) FROM t_arr)) AS g(s) test(> ) AS s(i) test-> ON (s.i <= array_upper(val, 1)); id | val +- 1 | 1 1 | 2 1 | 3 2 | 4 2 | 5 2 | 6 3 | 7 3 | 8 3 | 9 4 | 10 4 | 11 4 | 12 4 | 13 (13 rows) -- -- Second Way (by using contrib/intagg) -- SELECT id, int_array_enum(val) FROM t_arr; Regards. ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match