Re: [SQL] problem converting strings to timestamps with time zone

2010-04-28 Thread Tom Lane
Edward Ross writes: > Here is a sandbox example of what I mean. > CREATE TABLE test_0 > ( > string_value varchar(2047), > timestamp_value timestamp with time zone > ); > insert into test_0 >(string_value) > values >('2010-03-12 17:06:21-0800'), >('2009-08-14 1

[SQL] problem converting strings to timestamps with time zone

2010-04-28 Thread Edward Ross
Hi, I have a table with varchar and timestamp with time zone columns, among others. Insertions into this table are usually done by a java program; and there are many tens of thousands of records in the table. Recently, after changes in the java software, many timestamps values inadvertently

Re: [SPAM]-D] [SQL] How to find broken UTF-8 characters ?

2010-04-28 Thread Andreas
Hi, while writing the reply below I found it sounds like beeing OT but it's actually not. I just need a way to check if a collumn contains values that CAN NOT be converted from Utf8 to Latin1. I tried: Select convert_to (my_column::text, 'LATIN1') from my_table; It raises an error that says t

Re: [SQL] Inserting Multiple Random Rows

2010-04-28 Thread Gary Chambers
Justin (et al), > You now what might work In the interest of efficiency, I abandoned the quest for the perfect query and wrote my own function and used a modified version of depesz's get_random_id() function: CREATE OR REPLACE FUNCTION gen_fake_addresses() RETURNS INTEGER AS $gen_fake_addresses$

Re: [SQL] Inserting Multiple Random Rows

2010-04-28 Thread Gary Chambers
Justin, Thanks for the reply! > you need to generate a series of random numbers then select each record > one at a time out of cities table .  You will have to write a plsql > function to do this As any join will cause the result to be ordered. After modifying my search terms at Google, I've dis

Re: [SQL] Inserting Multiple Random Rows

2010-04-28 Thread Justin Graf
On 4/28/2010 1:48 PM, Gary Chambers wrote: > pen? > > The clouds parting, choirs of angels singing, and fireworks > celebrating the veil of my obtuseness being lifted, and my grasp and > command of SQL to be complete and infinite. None of which appears > will ever happen... > > -- Gary Chamber

Re: [SQL] Inserting Multiple Random Rows

2010-04-28 Thread Gary Chambers
Tom, > I believe the sub-SELECT will only get executed once, since it has no > dependency on the outer query. That seems to be the behavior its exhibiting. > What were you expecting to happen? The clouds parting, choirs of angels singing, and fireworks celebrating the veil of my obtuseness bein

Re: [SQL] Inserting Multiple Random Rows

2010-04-28 Thread Justin Graf
That won't work because Order by does not recompute Random() once gets a number it stops you need to generate a series of random numbers then select each record one at a time out of cities table . You will have to write a plsql function to do this As any join will cause the result to be order

Re: [SQL] Inserting Multiple Random Rows

2010-04-28 Thread Tom Lane
Gary Chambers writes: > INSERT INTO useraddrs(userid, addrdesc, city, stprov) > SELECT u.userid, 'Home', c.cityname, c.stateabbr > FROM users u, cities c > WHERE u.userid NOT IN (SELECT userid FROM useraddrs) > AND cid=(SELECT cid FROM cities ORDER BY RANDOM() LIMIT 1); > I am able to achieve

[SQL] Inserting Multiple Random Rows

2010-04-28 Thread Gary Chambers
All, I have a table of user addresses that I'm trying to randomly populate with data from a cities table. Using the following query: INSERT INTO useraddrs(userid, addrdesc, city, stprov) SELECT u.userid, 'Home', c.cityname, c.stateabbr FROM users u, cities c WHERE u.userid NOT IN (SELECT userid