Thread: Here is my problem

Here is my problem

From
Basavaraj
Date:
Now i want to insert data to the table....
the format should be

id | marks
----------
1  |50
1  |30
1  |30
....
....
2 |...
....

the actual query is

insert into table(id,marks) values(1,unnest(array[marks]))


But we should not use array and unnest but i want in this format

pls help..



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Here-is-my-problem-tp5766954.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


Re: need help

From
David Johnston
Date:
Basavaraj wrote
> i have two unrelated tables as their is no common column to apply joins or
> anything, so i want to join those tables...

I can understand being required to join them (for some unstated reason) but
a simple want does not seem a strong enough reason to go through the pain...


> ...using simple query...

If you have to join these tables together the complexity of the resultant
query should be irrelevant.  Furthermore how one defines "simple" is quite
subjective.


> finally the result shoule be
>
> name| address|email|mobileNo|firstname|lastName|
> --------------------------------------------------
> abc   some1    mail1   1234564 def          xyz
>
> 5 records               |   10 records
>
>                            |
>
> Very thankful for solution............

I have no clue what you mean when you indicate "5 records | 10 records" in
the final result.

I'm tempted to ask you leading questions but instead am going to ask that
you consider your goal more closely and be more explicit in your
description/request.

If you just want to go and play with it you can consider two possible
options:

SELECT * FROM tbl1 CROSS JOIN tbl2 --(this will return X times Y rows - or
10 times 5 = 50)

or <not valid SQL, just an example>

SELECT *
FROM (SELECT row_number, * FROM tbl1) t1
FULL OUTER JOIN (SELECT row_number, * FROM tbl2) t2 USING (row_number)
-- this will return 10 rows with 5 of them containing NULL values for t1
columns where t2 has row numbers not existing in t1.

What you are doing, by the example given, is wrong.  Proposing an
alternative is impossible since you have not explained WHY you feel you need
to do this or WHAT you are actually trying to accomplish.

David J.





--
View this message in context: http://postgresql.1045698.n5.nabble.com/Here-is-my-problem-tp5766954p5767617.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


need help

From
Basavaraj
Date:
i have two unrelated tables as their is no common column to apply joins or
anything, so i want to join those tables using simple query(only two tables
should be used and no common table) can you pls help me out how to do that.
I am new user to postgres

this is table format

table1                                                 table2

name| address|email|                     mobileNo|firstname|lastName|
----------------------                  ------------------------------
abc    some1   mail1                       1234564|def         |
:                                                 :
:                                                 :
                                                  :
:
:5 records                                  10 records


finally the result shoule be

name| address|email|mobileNo|firstname|lastName|
--------------------------------------------------
abc   some1    mail1   1234564 def          xyz

5 records               |   10 records

                           |

Very thankful for solution............





--
View this message in context: http://postgresql.1045698.n5.nabble.com/Here-is-my-problem-tp5766954p5767611.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


Re: need help

From
John R Pierce
Date:
On 8/16/2013 6:35 AM, Basavaraj wrote:
> finally the result shoule be
>
> name| address|email|mobileNo|firstname|lastName|
> --------------------------------------------------
> abc   some1    mail1   1234564 def          xyz
>
> 5 records               |   10 records
>
>                             |


First, a table is an unordered SET of tuples(rows).  it only has an
order when one is applied to it.   so which rows of table 1 would go
with what rows of table 2?

Second, if that 2nd table has 10 records and the first table only has 5,
what would those other 5 look like in your example?   no answer I can
think of makes sense.   all rows of a recordset have to have the same
fields.

If this data is unrelated, then it does not belong together in a relation.


--
john r pierce                                      37N 122W
somewhere on the middle of the left coast



Re: need help

From
Basavaraj
Date:
thanks for ur help,this was the requirement which assigned for us,so i had to
ask even though we are having many options.....thanks again



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Here-is-my-problem-tp5766954p5767778.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


thank you

From
Basavaraj
Date:
Ya i got the answer here is the code


SELECT *
FROM (SELECT row_number() over(), * FROM employee) t1
right outer JOIN (SELECT row_number() over(), * FROM managers) t2 on
t1.row_number=t2.row_number



Thank you



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Here-is-my-problem-tp5766954p5767787.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


Re: thank you

From
Alisa
Date:
   Hi,
        why do  you connect one table with the other? They are't any
relations between them. So I don't understand your point, I am somewhat
confused, you can refer to the following site:
http://www.postgresql.org/docs/9.0/static/queries-table-expressions.html
        http://my.oschina.net/Kenyon/blog/79543
> Ya i got the answer here is the code
>
>
> SELECT *
> FROM (SELECT row_number() over(), * FROM employee) t1
> right outer JOIN (SELECT row_number() over(), * FROM managers) t2 on
> t1.row_number=t2.row_number
>
>
>
> Thank you
>
>
>
> --
> View this message in context: http://postgresql.1045698.n5.nabble.com/Here-is-my-problem-tp5766954p5767787.html
> Sent from the PostgreSQL - general mailing list archive at Nabble.com.
>
>