[SQL] default value for select?

2005-05-09 Thread Mark Fenbers




I want to update a column in myTable.  The value this column is set to
depends on a nested select statement which sometimes returns 0 rows
instead of 1.  This is a problem since the column I'm trying to update
is set to refuse nulls.  Here's a sample:

update myTable set myColumn = (Select altColumn from altTable where
altColumn != 'XXX' limit 1) where myColumn = 'XXX';

MyColumn cannot accept nulls, but sometimes "Select altColumn ..."
returns 0 rows, and thus, the query fails.  

Is there a way to set a default value to be inserted into myColumn if
and when "select altColumn ..." returns zero rows?

Mark


begin:vcard
fn:Mark Fenbers
n:Fenbers;Mark
org:DoC/NOAA/NWS/OHRFC
adr:;;1901 South SR 134;Wilmington;OH;45177-9708;USA
email;internet:[EMAIL PROTECTED]
title:Sr. HAS Meteorologist
tel;work:937-383-0430 x246
x-mozilla-html:TRUE
url:http://weather.gov/ohrfc
version:2.1
end:vcard


---(end of broadcast)---
TIP 8: explain analyze is your friend


[SQL] Replacing a table with constraints

2005-05-13 Thread Mark Fenbers




I have a table called Counties which partially contains a lot bad
data.  By" bad data", I mean some records are missing; some exist and
shouldn't; and some records have fields with erroneous information. 
However, the majority of the data in the table is accurate.  I have
built/loaded a new table called newCounties with the same structure as
Counties, but contains no bad data.  My was  to completely replace the
contents of Counties with the contents of newCounties.  The problem is:
several other tables have Foreign Key constraints placed on Counties. 
Therefore, Pg will not let me 'DELETE FROM Counties;", nor will it let
me "DROP TABLE Counties;"  

I'm perplexed.  Can someone suggest how I can best get data from
Counties to look just like newCounties?

Mark


begin:vcard
fn:Mark Fenbers
n:Fenbers;Mark
org:DoC/NOAA/NWS/OHRFC
adr:;;1901 South SR 134;Wilmington;OH;45177-9708;USA
email;internet:[EMAIL PROTECTED]
title:Sr. HAS Meteorologist
tel;work:937-383-0430 x246
x-mozilla-html:TRUE
url:http://weather.gov/ohrfc
version:2.1
end:vcard


---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [SQL] Replacing a table with constraints

2005-05-13 Thread Mark Fenbers




True, but Counties has about 8 or 9 rules, view, or pk constraints
attached to it.  I don't want to break all these unless I knew of a way
to save off the SQL for them beforehand so I can easily rebuild them...
Mark

Ing. Jhon Carrillo wrote:

  
  
  
  Use  Drop
table YOUR_TABLE cascade
   
  Jhon Carrillo
Ingeniero en Computación
  Caracas - Venezuela
  
   
   
  - Original Message - 
  
From:
    Mark
Fenbers 
To:
pgsql-sql@postgresql.org 
Sent:
Friday, May 13, 2005 2:38 PM
Subject:
[SQL] Replacing a table with constraints


I have a table called Counties which partially contains a lot bad
data.  By" bad data", I mean some records are missing; some exist and
shouldn't; and some records have fields with erroneous information. 
However, the majority of the data in the table is accurate.  I have
built/loaded a new table called newCounties with the same structure as
Counties, but contains no bad data.  My was  to completely replace the
contents of Counties with the contents of newCounties.  The problem is:
several other tables have Foreign Key constraints placed on Counties. 
Therefore, Pg will not let me 'DELETE FROM Counties;", nor will it let
me "DROP TABLE Counties;"  

I'm perplexed.  Can someone suggest how I can best get data from
Counties to look just like newCounties?

Mark
 
 
---(end of broadcast)---
TIP 8: explain analyze is your friend
  



begin:vcard
fn:Mark Fenbers
n:Fenbers;Mark
org:DoC/NOAA/NWS/OHRFC
adr:;;1901 South SR 134;Wilmington;OH;45177-9708;USA
email;internet:[EMAIL PROTECTED]
title:Sr. HAS Meteorologist
tel;work:937-383-0430 x246
x-mozilla-html:TRUE
url:http://weather.gov/ohrfc
version:2.1
end:vcard


---(end of broadcast)---
TIP 6: Have you searched our list archives?

   http://archives.postgresql.org


[SQL] sub-selects

2005-05-16 Thread Mark Fenbers




Is there a way to make a query more efficient by executing a sub-select
only once?

In a query such as:

SELECT a, (select b from c where d = e limit 1), npoints( (select b
from c where d = e limit 1) )
    FROM f
    WHERE isValid( (select b from c where d = e limit 1) );

I do the same sub-select 3 times in the query.  I tried the following:

SELECT a, (select b from c where d = e limit 1) AS g,
npoints( g )
    FROM f
    WHERE isValid( g );

But this gave an error regarding "column 'g' does not exist".  How can
I avoid making the same sub-select 3 times? 

Mark


begin:vcard
fn:Mark Fenbers
n:Fenbers;Mark
org:DoC/NOAA/NWS/OHRFC
adr:;;1901 South SR 134;Wilmington;OH;45177-9708;USA
email;internet:[EMAIL PROTECTED]
title:Sr. HAS Meteorologist
tel;work:937-383-0430 x246
x-mozilla-html:TRUE
url:http://weather.gov/ohrfc
version:2.1
end:vcard


---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


[SQL] Aggregate Functions Template

2005-05-19 Thread Mark Fenbers
I need to create an aggregate function to do some math not currently 
provided by the available tools.  Can someone point to an example 
aggregate function syntax that I can use as a template for my own 
function.  I'm still a little green on some aspects of PostgreSQL and am 
drawing a blank on how to do this properly from scratch.

Thanks for the help!
Mark
begin:vcard
fn:Mark Fenbers
n:Fenbers;Mark
org:DoC/NOAA/NWS/OHRFC
adr:;;1901 South SR 134;Wilmington;OH;45177-9708;USA
email;internet:[EMAIL PROTECTED]
title:Sr. HAS Meteorologist
tel;work:937-383-0430 x246
x-mozilla-html:TRUE
url:http://weather.gov/ohrfc
version:2.1
end:vcard


---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])


Re: [SQL] Aggregate Functions Template

2005-05-20 Thread Mark Fenbers
Yes, your varlena links are what I was looking for as a source of help...
Thanks!
Mark
Michael Fuhr wrote:
On Thu, May 19, 2005 at 03:17:07PM -0400, Mark Fenbers wrote:
 

I need to create an aggregate function to do some math not currently 
provided by the available tools.  Can someone point to an example 
aggregate function syntax that I can use as a template for my own 
function.  I'm still a little green on some aspects of PostgreSQL and am 
drawing a blank on how to do this properly from scratch.
   

The General Bits newsletter has a few examples that might be helpful,
even if they're not quite what you're after:
http://www.varlena.com/varlena/GeneralBits/109.php
http://www.varlena.com/varlena/GeneralBits/4.html
There are sure to be some examples in the list archives -- just
search for "create aggregate":
http://archives.postgresql.org/
If these links don't help, then please post more details about what
you're trying to do and what trouble you're having.  If you have
any code that doesn't work the way you want but that helps show
what you're after, then go ahead and post it with an explanation
of what it does (or doesn't do) and what you'd like it to do (or
not do).
 

begin:vcard
fn:Mark Fenbers
n:Fenbers;Mark
org:DoC/NOAA/NWS/OHRFC
adr:;;1901 South SR 134;Wilmington;OH;45177-9708;USA
email;internet:[EMAIL PROTECTED]
title:Sr. HAS Meteorologist
tel;work:937-383-0430 x246
x-mozilla-html:TRUE
url:http://weather.gov/ohrfc
version:2.1
end:vcard


---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


[SQL] DBD::Pg on Enterprise 3

2005-05-20 Thread Mark Fenbers
A colleage of mine in another office has RedHat Enterprise 3 installed.  
We do not have this yet, but will in the fall.  According to him, the 
DBD::Pg module that has been a part of the Red Hat baseline from Redhat 
7.2 (or earlier) through RH Fedora Core has been removed from RH 
Enterprise 3 baseline.  Although the module is available for 
installation, this causes me alarm because our agency has rules 
regarding installing un-approved modules on official agency equipment.  
Can anyone tell me what the facts are regarding DBD::Pg and RHEL3??

Thank you!
Mark
begin:vcard
fn:Mark Fenbers
n:Fenbers;Mark
org:DoC/NOAA/NWS/OHRFC
adr:;;1901 South SR 134;Wilmington;OH;45177-9708;USA
email;internet:[EMAIL PROTECTED]
title:Sr. HAS Meteorologist
tel;work:937-383-0430 x246
x-mozilla-html:TRUE
url:http://weather.gov/ohrfc
version:2.1
end:vcard


---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


[SQL] Dumping table definitions

2005-07-18 Thread Mark Fenbers

I am looking for a way to reformat the information that is generated from
   \d mytable
into SQL syntax, such that the table can be recreated with 'psql -f 
mytable.sql' complete with index and constraint definitions.  I can do 
awk and sed commands to do this if I need to, but first wanted to check 
if Pg already had tools to export the table structure (without the 
data).  Does it?


Also, Is there a way to export the structure of all tables at once 
instead of one table at a time?


Mark
begin:vcard
fn:Mark Fenbers
n:Fenbers;Mark
org:DoC/NOAA/NWS/OHRFC
adr:;;1901 South SR 134;Wilmington;OH;45177-9708;USA
email;internet:[EMAIL PROTECTED]
title:Sr. HAS Meteorologist
tel;work:937-383-0430 x246
x-mozilla-html:TRUE
url:http://weather.gov/ohrfc
version:2.1
end:vcard


---(end of broadcast)---
TIP 4: Have you searched our list archives?

   http://archives.postgresql.org


[SQL] APPEND INTO?

2005-12-01 Thread Mark Fenbers
I want to SELECT INTO mytable WHERE (criteria are met), except that I 
want to APPEND into an existing table the rows that are selected, 
instead of creating a new table (which SELECT INTO will do).  How can 
this be done?


(Is this what the "FOR UPDATE OF tablename" clause is for?)

Mark

---(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


[SQL] Just 1 in a series...

2005-12-02 Thread Mark Fenbers
I currently have a working SQL that SELECTs all records whose 
'river_stage' column exceeds the 'flood_stage' column.  (Very simple -- 
no applause needed.)  Typically, if I get one record, I get a 
consecutive series of them since rivers rise and fall in a continuous 
fashion, and usually respond lethargically when this much water is in 
the rivers.  This time-series of river stages all have (another column 
called) 'event_id' set to the same integer value, so long as the river 
has not fallen below flood stage (which will trigger the event_ID to be 
incremented). 

However, I only want the first occurrence of a such a series (where the 
event_id is the same), what SQL syntax should I use to do this? 

I tried playing with different combinations using DISTINCT, GROUP BY, 
and LIMIT 1, but I have had no success getting the results I'm looking 
for, thus far.  So I figured I might get farther faster by asking the 
group.  I must be misunderstanding the "GROUP BY" clause because I get 
an error essentially stating that I need to list every column in the 
SELECT list in the GROUP BY list (which makes it ineffective)...


My knots are tangled.  Can someone please send advice regarding this issue?

Mark

---(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


Re: [SQL] Just 1 in a series...

2005-12-02 Thread Mark Fenbers



You might find the "DISTINCT ON" syntax does just what you want --- see
the "weather report" example on the SELECT reference page.  It's not
standard SQL though.

This works!  Thanks! 


What would have to be done if I needed a standard SQL solution?
Mark


---(end of broadcast)---
TIP 4: Have you searched our list archives?

  http://archives.postgresql.org


[SQL] pgadmin

2006-01-23 Thread Mark Fenbers
I'm having trouble with installing pgadmin.  If this is not the 
apporpriate group for seeking help with this, please excuse me and tell 
the correct one.  I have not found anything else more appropriate.


'make' for pgadmin fails, I think it is because I don't have wxWidgets.  
wxWidgets fails.  I think it is because I don't have Motif/Lesstif.  
Lesstif fails because of another large list of dependencies.  For Pete's 
sake!  Do I have to double the size of my Operating System (which is 
Linux, Redhat 9, BTW) just to install pgadmin?  I've installed lots of 
software packages over the years, mostly through the 
./configure;make;make install sequence, but this is the most difficult 
installation I've ever encountered.  I don't have a stripped down 
version of the O/S either... it's pretty much a full install of RH9.


I'm thinking that I must be doing something wrong.  PostgreSQL and 
PostGIS installed without any problems, but this single utility 
(pgadmin) is really throwing me for a loop.


Does anyone have any ideas I could try?

Mark

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


[SQL] group by complications

2006-02-13 Thread Mark Fenbers

select l.lid,l.fs,max(h.obstime) from location as l
inner join height as h on h.lid = l.lid
where l.fs > 0.0
group by l.lid,l.fs;

The above query works as expected in that is fetches the lid, fs and 
time of the latest observation in the height table (for the 
corresponding lid), but I also want to fetch (i.e., add to the select 
list) the corresponding reading (h.obsvalue) which occurs at 
max(h.obstime).  I'm having trouble formulating the correct SQL syntax 
to pull out the l.lid, l.fs, and the most recent h.obvalue (with or 
without the time that it occurred).


Logistically, I want to do something like this:

select l.lid,l.fs,most_recent(h.obsvalue) from location as l
inner join height as h on h.lid = l.lid
where l.fs > 0.0
group by l.lid,l.fs;

Can someone offer hints, please?

Mark

---(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


Re: [SQL] group by complications

2006-02-16 Thread Mark Fenbers




Wow!  I didn't know you could have a (select ...) as a replacement for
a 'from' table/query.  Your SQL worked as-is, except I had to add a
'limit 1' to the first subquery.

Thanks!  I would have never figured that out on my own!

Mark

chester c young wrote:

  --- Mark Fenbers <[EMAIL PROTECTED]> wrote:

  
  
select l.lid,l.fs,max(h.obstime) from location as l
inner join height as h on h.lid = l.lid
where l.fs > 0.0
group by l.lid,l.fs;

The above query works as expected in that is fetches the lid, fs and 
time of the latest observation in the height table (for the 
corresponding lid), but I also want to fetch (i.e., add to the select
list) the corresponding reading (h.obsvalue) which occurs at 
max(h.obstime).  I'm having trouble formulating the correct SQL
syntax 
to pull out the l.lid, l.fs, and the most recent h.obvalue (with or 
without the time that it occurred).

Logistically, I want to do something like this:

select l.lid,l.fs,most_recent(h.obsvalue) from location as l
inner join height as h on h.lid = l.lid
where l.fs > 0.0
group by l.lid,l.fs;


  
  
use your original query as part of the from clause, then add columns to
it through a subquery or a join.  try something like this:

select q1.*,
(select obsvalue from height where lid=q1.lid and obstime=q1.obstime)
  as obsvalue
from
(select l.lid,l.fs,max(h.obstime) as obstime1 from location as l
inner join height as h on h.lid = l.lid
where l.fs > 0.0
group by l.lid,l.fs ) q1;


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings

  





[SQL] Change date format through an environmental variable?

2006-03-01 Thread Mark Fenbers
I want to get Pg (v7.4.7) to output a date field in a different format 
than -mm-dd through the use of an environmental variable (because I 
have no access the SQL).  Is this possible?  I know about the DATESTYLE 
variable, but that seems to work only within a query transaction, and 
has no effect if trying to set it as an envvar.


Mark

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [SQL] Change date format through an environmental variable?

2006-03-01 Thread Mark Fenbers
I found PGDATESTYLE that solves my problem, but ever since, I've been 
looking for a comprehensive list of environmental variables that Pg 
recognizes, but haven't been able to find such a list in any of the 
books I looked in or the man pages.  Anyone know where I can find such a 
list?

Mark

Mark Fenbers wrote:
I want to get Pg (v7.4.7) to output a date field in a different format 
than -mm-dd through the use of an environmental variable (because 
I have no access the SQL).  Is this possible?  I know about the 
DATESTYLE variable, but that seems to work only within a query 
transaction, and has no effect if trying to set it as an envvar.


Mark

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings



---(end of broadcast)---
TIP 4: Have you searched our list archives?

  http://archives.postgresql.org


[SQL] Does PG have a database

2006-05-22 Thread Mark Fenbers
I have working PostgreSQL databases on 3 of my ~30 Linux boxes.  I want 
my software to be able to determine which of my 30 boxes have functional 
databases on them.  Since Pg is part of the baseline distro, merely 
checking for the existence of an executable doesn't solve my problem.


I tried looping through my list of hosts and running the command:
   psql -h $host --list
but this fails on a box with a database with the same error code as on a 
box that doesn't have a database, if my PGUSER isn't set and my login ID 
is not the username of the database.  The PGUSER setting might differ 
for each host, so specifying this in the software is not practical.


Bottom line:  What trick can I use to determine whether a box has a 
living, breathing Pg database if I don't know the DB owner? 


Mark

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


[SQL] drop PW

2009-06-13 Thread Mark Fenbers
I have created a new 8.3 version DB and populated it.  A specific user 
of this database (george) has been setup with a password, so that every 
time I use psql or some other utility, I need to supply this password.  
So I want to drop the password authentication.  I tried rerunning 
createuser (and just pressing Enter when prompted for the new password), 
but it complains that the user already exists.  I can't drop the user 
because this user owns the DB and all the tables.  My postgresql books 
are all for 7.x, and suggests altering the pg_shadow table (which seems 
risky to me).  I tried:

ALTER USER george PASSWORD '';
and that looked like it succeeded, but running psql again prompted me 
and when I just hit Enter, it complained that no password was supplied.


So how do I turn off being prompted for a password for george.  (I am 
aware of the security risks...)


Mark

--
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] Rewrite without correlated subqueries

2009-08-20 Thread Mark Fenbers




Try putting your subqueries into temporary tables, first, inside a
BEGIN ... COMMIT block.  But your subqueries would produce the
negative, i.e., everything except where sitescategory.idsites =
ps.idsites.  Then reference these temp tables in your query with inner
or outer joins as appropriate.  Your new query would not include the
... IN (  ) syntax...

Mark

bricklen wrote:
Hi All,
  
I'm having some trouble wrapping my head around the syntax to rewrite a
query using correlated subqueries, to using outer joins etc.
  
The query:
  
SELECT  ps.userid,
   SUM( ps.hits ) as numhits
FROM primarystats AS ps
  INNER JOIN camp ON camp.id = ps.idcamp
  INNER JOIN sites ON sites.id = ps.idsite
WHERE camp.idcatprimary NOT IN ( SELECT idcategory FROM sitescategory
WHERE sitescategory.idsites = ps.idsites )
AND camp.idcatsecondary NOT IN ( SELECT idcategory FROM sitescategory
WHERE sitescategory.idsites = ps.idsites )
GROUP BY ps.userid;
  
Because I am rewriting this query to use Greenplum, I cannot use
correlated subqueries (they are not currently supported).
  
Can anyone suggest a version that will garner the same results? I tried
with OUTER JOINS and some IS NULLs, but I couldn't get it right.
  
Thanks!
  
bricklen
  
  





[SQL] Simple aggregate query brain fart

2010-03-18 Thread Mark Fenbers

I want to do:

SELECT id, count(*) FROM mytable WHERE count(*) > 2 GROUP BY id;

But this doesn't work because Pg won't allow aggregate functions in a 
where clause.  So I modified it to:


SELECT id, count(*) AS cnt FROM mytable WHERE cnt > 2 GROUP BY id;

But Pg still complains (that column cnt does not exist).  When using an 
GROUP/ORDER BY clause, I can refer to a column number (e.g., GROUP BY 1) 
instead of a column name, but how can I refer to my unnamed second 
column in my where clause?


Mark

<>
-- 
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] Simple aggregate query brain fart

2010-03-18 Thread Mark Fenbers




Thanks, Joe and Tom.  You cleared the webs out of my brain.  I used
HAVING before, but not lately and I got rusty.
Mark

Tom Lane wrote:

  Mark Fenbers  writes:
  
  
I want to do:
SELECT id, count(*) FROM mytable WHERE count(*) > 2 GROUP BY id;

  
  
  
  
But this doesn't work because Pg won't allow aggregate functions in a 
where clause.

  
  
Use HAVING, not WHERE.  The way you are trying to write the query is
meaningless because WHERE filters rows before grouping/aggregation.
HAVING filters afterwards, which is when it makes sense to put a
condition on count(*).

			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] import ignoring duplicates

2010-05-16 Thread Mark Fenbers
I am using psql's \copy command to add records to a database from a 
file.  The file has over 100,000 lines.  Occasionally, there is a 
duplicate, and the import ceases and an internal rollback is performed.  
In other words, no data is imported even if the first error occurs near 
the end of the file.


I am looking for an option/switch to tell psql (or the \copy command) to 
skip over any duplicate key constraint viloations and continue to load 
any data that doesn't violate a duplicate key constraint.  Is there such 
an option?


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


[SQL] Aggregates puzzle

2011-03-31 Thread Mark Fenbers

SQL gurus,

I have a table with 4 columns:  lid(varchar), value(float), 
obstime(datetime), event_id(integer)


I want to find the MAX(value) and the time and date that it occurred 
(obstime) in each group of rows where the lid and event_id are the 
same.  What I have works correctly in identifying the MAX(value) for the 
given group, but I'm having trouble getting the corresponding obstime to 
be reported along with it.


Here's the SQL I have:

SELECT lid, MAX(value), event_id
FROM flood_ts
GROUP BY lid, event_id
ORDER BY lid;

If I add "obstime" to the SELECT list, then I need to add "value" to the 
GROUP BY clause, which makes the MAX(value) function report *each row* 
as a maximum.


So, how can I revise my SQL to report the obstime that the MAX(value) 
occurred?


Any help is sincerely appreciated.

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


[SQL] complex query

2012-10-27 Thread Mark Fenbers

  
  
I have a query:
SELECT id, SUM(col1), SUM(col2) FROM mytable WHERE condition1 = true
GROUP BY id;

This gives me 3 columns, but what I want is 5 columns where the next
two columns -- SUM(col3), SUM(col4) -- have a slightly different
WHERE clause, i.e., WHERE condition2 = true.

I know that I can do this in the following way:
SELECT id, SUM(col1), SUM(col2), (SELECT SUM(col3) FROM mytable
WHERE condition2 = true), (SELECT SUM(col4) FROM mytable WHERE
condition2 = true) FROM mytable WHERE condition1 = true GROUP BY id;

Now this doesn't seem to bad, but the truth is that condition1 and
condition2 are both rather lengthy and complicated and my table is
rather large, and since embedded SELECTs can only return 1 column, I
have to repeat the exact query in the next SELECT (except for using
"col4" instead of "col3").  I could use UNION to simplify, except
that UNION will return 2 rows, and the code that receives my
resultset is only expecting 1 row.

Is there a better way to go about this?

Thanks for any help you provide.
Mark

  

<>
-- 
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] complex query

2012-10-27 Thread Mark Fenbers

  
  

  
I'd do somethings like:

select * from (
select id, sum(col1), sum(col2) from tablename group by yada
   ) as a [full, left, right, outer] join (
select id, sum(col3), sum(col4) from tablename group by bada
) as b
on (a.id=b.id);

and choose the join type as appropriate.

Thanks!  Your idea worked like a champ!
Mark

  

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


[SQL] Fun with Dates

2012-10-29 Thread Mark Fenbers

  
  
Greetings,

I want to be able to select all data going back to the beginning of
the current month.  The following portion of an SQL does NOT work,
but more or less describes what I want...

... WHERE obstime >= NOW() - INTERVAL (SELECT EXTRACT (DAY FROM
NOW() ) ) + ' days'

In other words, if today is the 29th of the month, I want to select
data that is within 29 days old... WHERE obstime >= NOW() -
INTERVAL '29 days'

How do I craft a query to do use a variable day of the month?

Mark
  

<>
-- 
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] Fun with Dates

2012-10-29 Thread Mark Fenbers

  
  

Or the
  other way round: anything that is equal or greater than the first
  
  of the current month:
  
  
  select ...
  
  from foobar
  
  where obstime >= date_trunc('month', current_date);
  

I knew it had to be something simple!   thanks!
Mark
  

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


[SQL] Informix Schema -> PostgreSQL ?

2007-07-03 Thread Mark Fenbers
I am an ex-Informix convert.  Informix used the term "schema" to refer 
to the SQL-format definition of how a table or view was created.  E.g., 
CREATE TABLE john ( char(8) lid, ...);  Some views we have are quite 
complex (and not created by me) and I want to create a similar one in 
Pg.  If I could see the view in this SQL format, then I could use SQL to 
create another one using this as a template.


pgadmin3 can show this definition in SQL format, but I can't use 
pgadmin3 on a certain box.  How can I show information in Pg (psql) the 
way that Informix would show a schema?


BTW, what does PostgreSQL call this (what Informix calls a schema)??

Mark

---(end of broadcast)---
TIP 4: Have you searched our list archives?

  http://archives.postgresql.org


[SQL] vacuum in single-user mode

2008-08-08 Thread Mark Fenbers
A seldom-used database of mine was not recently vacuumed and I've run 
into the error: FATAL: database is not accepting commands to avoid 
wraparound data loss in database "stop"HINT: Stop the postmaster and 
use a standalone backend to vacuum database "stop".  In fact, I get this 
error while trying to run "vacuumdb -U postgres -a" (and logged in as 
postgres).


I haven't the foggiest idea what this means but googled the error and 
found a site that seems to suggest that I need to run the vacuum in 
"single-user" mode before running VACUUM FULL, but I cannot find out how 
to do that, either.


Can anyone lend some advice, please?

Mark

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