Re: [SQL] map row in one table with random row in another table

2012-03-07 Thread rverghese
That's cool, thanks! 
Yeah I just want to create some test data, so it's not something I would run
often.

--
View this message in context: 
http://postgresql.1045698.n5.nabble.com/map-row-in-one-table-with-random-row-in-another-table-tp5542231p5545510.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] map row in one table with random row in another table

2012-03-07 Thread Igor Neyman
> -Original Message-
> From: rverghese [mailto:ri...@hotmail.com]
> Sent: Tuesday, March 06, 2012 4:01 PM
> To: pgsql-sql@postgresql.org
> Subject: map row in one table with random row in another table
> 
> Hi, I am trying to map every row in one table with a random row in
> another.
> So for e.g. , for each network in 1 table I am trying to map random
> segments from the other table. I have this sql below, but it always
> applies the same random segment that it picks to all the rows for the
> network. I want each row to have a random segment value. I'm just
using
> the generate_series function to generate id's as an e.g.
> Any suggestions?
> 
> My Query
> select id, seg_list from  (select generate_series(1,10) as id) as X,
> (select segment  from segments  order by random() limit 1 ) as Y
> 
> I get
> 
> 1;'cob0002'
> 2;'cob0002'
> 3;'cob0002'
> 4;'cob0002'
> 5;'cob0002'
> 6;'cob0002'
> 7;'cob0002'
> 8;'cob0002'
> 9;'cob0002'
> 10;'cob0002'
> 
> What I want is
> 
> 1;'cob0002'
> 2;'cob0008'
> 3;'cob0006'
> 4;'cob0004'
> 5;'cob0002'
> 6;'cob0007'
> 7;'cob0003'
> 8;'cob0004'
> 9;'cob0009'
> 10;'cob0001'
> 

Try this:

Select distinct on (id) id, segment
From (select generate_series(1,10) as id) as X,
 (select segment  from segments) as Y
Order by id, random();

Depending on the size of your tables, performance could become an issue.

Regards,
Igor Neyman


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


Re: [SQL] Type Ahead Issue

2012-03-07 Thread Tom Lane
Carlos Mennens  writes:
> Am I missing something here? When the command is on one line, auto
> complete works fine but when I break it up as show above in the 2nd
> example, it acts like 'COLUMN' isn't even a valid option but if I
> manually type the word 'COLUMN' and finish the command, it works.

Yeah, the autocompletion logic can only "see" the current line of input,
so in your second example it has no idea that this is an ALTER TABLE
command.  My recollection is that there's no very nice way around that
given the limitations of the readline callback interface, though maybe
if somebody got ambitious they could improve it.

regards, tom lane

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


[SQL] Type Ahead Issue

2012-03-07 Thread Carlos Mennens
I don't know if this is an issue with my client (Psql) or if it's
something I'm doing wrong but I've noticed this issue before and can't
figure it out. When I'm using the psql client, I really rely on the
tab / type ahead auto completion. When I run my command on one single
line, it works fine but when I break my line up into segments, it
doesn't understand what I'm trying to do:

ALTER TABLE meh ALTER C (if you press 'tab' after the 'c', psql knows
the only logical option is 'COLUMN'.

When I do the following, I don't get the same results:

ALTER TABLE meh
ALTER C (when I press 'tab' after 'C' to auto complete 'COLUMN', I get
the options only for 'COLLATION' or 'CONVERSION'. Why does it do this?
Am I missing something here? When the command is on one line, auto
complete works fine but when I break it up as show above in the 2nd
example, it acts like 'COLUMN' isn't even a valid option but if I
manually type the word 'COLUMN' and finish the command, it works. Why
is this acting this way?

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


[SQL] Re-Sync Stand By Server

2012-03-07 Thread Adam Cornett
I have 2 identical machines, (Ubuntu 10.04 LTS running 9.1.2 from Martin
Pitt's PPA) setup with streaming asynchronous replication.
Recently I had to take the standby down for some extended maintenance, and
when it came back up it was waiting for a WAL segment that had since been
removed from the primary.  I then shutdown the server, took a new base
backup of the primary and copied it over (as per the directions in the
streaming wiki) and cleared out the wal segments in the
pg_xlog directory of the standby and tried to start it again, but now its
not accepting connections and is looking for that wal file in the startup
process:

postgres 10090 10089  0 12:38 ?00:00:00 postgres: startup process
waiting for 0001005200E9

However, segment 5200E9 is no longer on the primary, which is about a
week ahead:

postgres@pg1:~$  psql -c "SELECT pg_current_xlog_location()"
 pg_current_xlog_location
--
 58/8E1B8D98

So, how do I get the standby to catch up to "catch up" to the primary?

-Adam Cornett


Re: [SQL] [ADMIN] pg_dump : no tables were found.

2012-03-07 Thread Julien Rouhaud
On Tue, Mar 6, 2012 at 7:22 AM, Piyush Lenka  wrote:

> Hi,
>
> I m trying to take backup of data of a particular table using pg_dump.
> I used double quotes for table name but output is :
> pg_dump : no tables were found.
>
> Command used :
> -h localhost -p 5432 -U postgres -W -F p -a -t '"TestTable"' -f
> DbBackup/BackupTableActions.sql TestDataBase
>
> This problem only shows when there is a upper case character in my table
> name.
> Please Help
>
> Thanks & Regards
> Piyush
>

Hi
You can try -t '"TestTable"' or -t \"TestTable\"