[SQL] how to cast this ?

2002-09-12 Thread juerg . rietmann
Hello there I have a db table with two char fields : log_date char(10) log_time char(8) I added a new field log_timestamp of type timestamptz How do I take the data from log_date and log_time and put it into log_timestamp ? update log set log_timestamp = cast (log_date as timestamp) || cast (

Re: [SQL] how to cast this ?

2002-09-12 Thread Oliver Elphick
On Thu, 2002-09-12 at 10:22, [EMAIL PROTECTED] wrote: > Hello there > > I have a db table with two char fields : > > log_date char(10) > log_time char(8) > > I added a new field log_timestamp of type timestamptz > > How do I take the data from log_date and log_time and put it into > log_timest

[SQL] still sorting and casting problems

2002-09-12 Thread juerg . rietmann
Hello there Unfortunately, I can't change the fieldtype that easy because other applications use the date as char(10) field as well. I need to sort the query by the log_date desc (log_date is char(10)). I tried the following without success : select id, log_date from userlog order by cast (log

Re: [SQL] reset sequence

2002-09-12 Thread Ludwig Lim
--- Ricardo Javier Aranibar León <[EMAIL PROTECTED]> wrote: > Hi List, > > I need that somebody help me. > First, I use PostgreSQL 7.0.3 for linux. > I need reset my sequence but that it begin in 1 > again when a use nextval. > And I have been search in > http://archives.postgresql.org/ about re

Re: [SQL] reset sequence

2002-09-12 Thread Michael Paesold
Ludwig Lim wrote: > --- Ricardo Javier Aranibar León > <[EMAIL PROTECTED]> wrote: > > Hi List, > > > > I need that somebody help me. > > First, I use PostgreSQL 7.0.3 for linux. > > I need reset my sequence but that it begin in 1 > > again when a use nextval. > > And I have been search in > > htt

Re: [SQL] Rules and Triggers: another question

2002-09-12 Thread Michael Paesold
Jerome Chochon wrote: > Thanks for your answer but i have another question. > Which one is the faster ? > > If i write this trigger... > CREATE TRIGGER trigger_name > BEFORE DELETE > ON table_name > FOR EACH ROW EXECUTE PROCEDURE function(); > > and this rule: > CREATE RULE name_rule AS > ON DE

[SQL] Select the max on a field

2002-09-12 Thread Gaetano Mendola
Hi all, Suppose that I have a table like this: att_1 |att_2 |att_3 | att_4 1 | a |y |y1 2 | b |y |y2 3 | a |xx |y3 4 | c |zz |y4 5

Re: [SQL] Select the max on a field

2002-09-12 Thread Gaetano Mendola
"Gaetano Mendola" <[EMAIL PROTECTED]> wrote in message alq3mr$2s7o$[EMAIL PROTECTED]">news:alq3mr$2s7o$[EMAIL PROTECTED]... > Hi all, > > Suppose that I have a table like this: > > > att_1 |att_2 |att_3 | att_4 > > 1 | a |y |

Re: [SQL] still sorting and casting problems

2002-09-12 Thread Stephan Szabo
On Thu, 12 Sep 2002 [EMAIL PROTECTED] wrote: > > Hello there > > Unfortunately, I can't change the fieldtype that easy because other > applications use the date as char(10) field as well. > > I need to sort the query by the log_date desc (log_date is char(10)). I > tried the following without suc

Re: [SQL] still sorting and casting problems

2002-09-12 Thread Jeff Eckermann
--- [EMAIL PROTECTED] wrote: > I need to sort the query by the log_date desc > (log_date is char(10)). I > tried the following without success : > > select id, log_date from userlog order by cast > (log_date as date) desc > > select id, log_date from userlog order by > date(log_date) desc > >

Re: [SQL] Select the max on a field

2002-09-12 Thread Stephan Szabo
On Thu, 12 Sep 2002, Gaetano Mendola wrote: > Hi all, > > Suppose that I have a table like this: > > > att_1 |att_2 |att_3 | att_4 > > 1 | a |y |y1 > 2 | b |y |y2 > 3 | a |x

Re: [SQL] Select the max on a field

2002-09-12 Thread Jeff Eckermann
--- Gaetano Mendola <[EMAIL PROTECTED]> wrote: > > "Gaetano Mendola" <[EMAIL PROTECTED]> wrote in > message > alq3mr$2s7o$[EMAIL PROTECTED]">news:alq3mr$2s7o$[EMAIL PROTECTED]... > > Hi all, > > > > Suppose that I have a table like this: > > > > > > att_1 |att_2 |att_3 | att_4 > >

[SQL] Performance inside and outside view ( WAS Re: Select the max on a field )

2002-09-12 Thread Gaetano Mendola
"Stephan Szabo" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > select distinct on (att_2) * from test > order by att_2, att_1 desc; Yes that's right it's help me, but here the optimizer have some problems: CREATE VIEW last_user_logs AS SELECT DISTINCT ON (i

Re: [SQL] Performance inside and outside view ( WAS Re: Select the max on a field )

2002-09-12 Thread Tom Lane
"Gaetano Mendola" <[EMAIL PROTECTED]> writes: > Yes that's right it's help me, > but here the optimizer have some problems: What's the datatype of id_user, and why are you quoting the compared constant in some cases but not others? I don't think the difference has anything to do with the view he

Re: [SQL] Performance inside and outside view ( WAS Re: Select the

2002-09-12 Thread Stephan Szabo
On Thu, 12 Sep 2002, Tom Lane wrote: > "Gaetano Mendola" <[EMAIL PROTECTED]> writes: > > Yes that's right it's help me, > > but here the optimizer have some problems: > > What's the datatype of id_user, and why are you quoting the compared > constant in some cases but not others? I don't think

Re: [SQL] Performance inside and outside view ( WAS Re: Select the max on a field )

2002-09-12 Thread Gaetano Mendola
"Tom Lane" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > "Gaetano Mendola" <[EMAIL PROTECTED]> writes: > > Yes that's right it's help me, > > but here the optimizer have some problems: > > What's the datatype of id_user, and why are you quoting the compared >

Re: [SQL] Performance inside and outside view ( WAS Re: Select the

2002-09-12 Thread Stephan Szabo
On Thu, 12 Sep 2002, Gaetano Mendola wrote: > > "Tom Lane" <[EMAIL PROTECTED]> wrote in message > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > "Gaetano Mendola" <[EMAIL PROTECTED]> writes: > > > Yes that's right it's help me, > > > but here the optimizer have some problems: > > > > What's the

[SQL] Latitude / Longitude

2002-09-12 Thread Tim Perdue
Hi Folks - I'm working on a global weather database for a client and have hit an issue which I'm sure has been solved before. Unfortunately, the site search doesn't pull up anything. Essentially, I've got two tables, one with city/county/lat/long and another with lat/long/weather data. None of

Re: [SQL] Latitude / Longitude

2002-09-12 Thread Larry Rosenman
Look at contrib/earthdistance, I **think** it does what you need. LER On Thu, 2002-09-12 at 12:44, Tim Perdue wrote: > Hi Folks - > > I'm working on a global weather database for a client and have hit an issue > which I'm sure has been solved before. Unfortunately, the site search doesn't > pul

Re: [SQL] Performance inside and outside view ( WAS Re: Select the

2002-09-12 Thread Tom Lane
Stephan Szabo <[EMAIL PROTECTED]> writes: > On Thu, 12 Sep 2002, Tom Lane wrote: >> What's the datatype of id_user, and why are you quoting the compared >> constant in some cases but not others? I don't think the difference >> has anything to do with the view here ... > At least in current sourc

[SQL] LIMIT within UNION?

2002-09-12 Thread Andrew Perrin
Greetings- I have a table of participants to be contacted for a study. Some are in the "exposure" group, others in the "control" group. This is designated by a column, typenr, that contains 1 for exposure, 2 for control. The complication is this: I need to select 200 total. The 200 number should

Re: [SQL] LIMIT within UNION?

2002-09-12 Thread Tom Lane
Andrew Perrin <[EMAIL PROTECTED]> writes: > SELECT ... FROM participants > WHERE typenr=1 AND > UNION > SELECT ... FROM participants > WHERE typenr=2 LIMIT 172 > ORDER BY zip; I think you need SELECT * FROM ( SELECT ... FROM participants WHERE typenr=1 AND UNION (SELECT ... FROM participants W

Re: [SQL] LIMIT within UNION?

2002-09-12 Thread Roland Roberts
> "Andrew" == Andrew Perrin <[EMAIL PROTECTED]> writes: Andrew> What I've done is to write a script that counts the number Andrew> of eligible exposure candidates: Andrew> SELECT count(*) FROM participants WHERE Andrew> AND typenr=1 Andrew> Then subtract that number (c

Re: [GENERAL] [SQL] Latitude / Longitude

2002-09-12 Thread Bruno Wolff III
On Thu, Sep 12, 2002 at 12:49:21 -0500, Larry Rosenman <[EMAIL PROTECTED]> wrote: > Look at contrib/earthdistance, I **think** it does what you need. There isn't an index for the distance operator. You can use boxes to limit the candidates if there is a small bound on how far apart points can b

Re: [SQL] LIMIT within UNION?

2002-09-12 Thread Andrew Perrin
Thanks! That did it. The inner parens are necessary - without them the ORDER BY seems to be parsed as part of the second subquery and is therefore a syntax error. Best, Andy -- Andrew J Perrin - http://www.unc.edu/~aperrin Assi

Re: [SQL] LIMIT within UNION?

2002-09-12 Thread Andrew Perrin
On 12 Sep 2002, Roland Roberts wrote: > > "Andrew" == Andrew Perrin <[EMAIL PROTECTED]> writes: > ... > Can you do this via a subselect: > > SELECT * FROM > ( SELECT ... FROM participants > WHERE typenr=1 AND > UNION > SELECT ... FROM participants > WHERE typen

Re: [SQL] Latitude / Longitude

2002-09-12 Thread Tim Perdue
On Thu, Sep 12, 2002 at 12:49:21PM -0500, Larry Rosenman wrote: > Look at contrib/earthdistance, I **think** it does what you need. Thanks, yeah this starts to get me into the realm of what I need. It still has to run every possible permutation to figure out which one is closest for each postalco

Re: [SQL] LIMIT within UNION?

2002-09-12 Thread Stephan Szabo
On Thu, 12 Sep 2002, Andrew Perrin wrote: > Greetings- > > I have a table of participants to be contacted for a study. Some are in > the "exposure" group, others in the "control" group. This is designated by > a column, typenr, that contains 1 for exposure, 2 for control. > > The complication is

Re: [SQL] LIMIT within UNION?

2002-09-12 Thread Andrew Perrin
On Thu, 12 Sep 2002, Stephan Szabo wrote: > On Thu, 12 Sep 2002, Andrew Perrin wrote: > > > Greetings- > > > > I have a table of participants to be contacted for a study. Some are in > > the "exposure" group, others in the "control" group. This is designated by > > a column, typenr, that contain

Re: [SQL] LIMIT within UNION?

2002-09-12 Thread Tom Lane
Andrew Perrin <[EMAIL PROTECTED]> writes: > Interesting - this would count on the UNION including all cases in the > first query before those in the second query. Are UNIONed records > presented in any predictable order? If you can use UNION ALL then this would be pretty safe to rely on. If you m

Re: [SQL] LIMIT within UNION?

2002-09-12 Thread Josh Berkus
Andrew, Another approach, one that does not require you to know before constructing the query how many eligible subjects there are, is not to use a union at all: SELECT * FROM ( SELECT ... , zip FROM participants WHERE (typenr = 1 and ) DESC LIMIT 200 ) p1 ORDER BY zip; The inner query gives y

Re: [SQL] [GENERAL] Latitude / Longitude

2002-09-12 Thread Joe Conway
Tim Perdue wrote: > Hi Folks - > > I'm working on a global weather database for a client and have hit an issue > which I'm sure has been solved before. Unfortunately, the site search doesn't > pull up anything. > > Essentially, I've got two tables, one with city/county/lat/long and another

[SQL] DISTINCT

2002-09-12 Thread Rudi Starcevic
Hello, I'd like to select from one table ( contains duplicates ) into a new table. However the new table is exactly the same as the original ( duplicates included ) I think I have a problem with my DISTINCT clause - sql below. It seems the DISTINCT is applied to the whole row not just the 'phon

Re: [SQL] DISTINCT

2002-09-12 Thread Christopher Kings-Lynne
> SELECT > DISTINCT phone, > company_name, > address, > state, > idc_desc_1, > street_number, > street_name, > street_xtra, > suburb, > postcode, > area_code, > ac_phone, > fax_area_code, > fax_phone, > fax_ac_phone, > latitude, >

Re: [SQL] DISTINCT

2002-09-12 Thread Rudi Starcevic
Christopher, Thank you. I though if I'm lucky Chris will be online and will see that one. Kind regards Rudi. ---(end of broadcast)--- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere"

[SQL] DISTINCT ON

2002-09-12 Thread Rudi Starcevic
Hi, Just quickly, DISTINCT ON - Is that Postgresql only ? Thanks ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/users-lounge/docs/faq.html

Re: [SQL] DISTINCT ON

2002-09-12 Thread Christopher Kings-Lynne
Don't know. I've seen it elsewhere so it might even be "standard". Chris > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED]]On Behalf Of Rudi Starcevic > Sent: Friday, 13 September 2002 10:50 AM > To: [EMAIL PROTECTED] > Subject: [SQL] DISTINCT ON > > > Hi, >