[SQL] function parameters : bug?

2005-07-13 Thread Richard Hayward
pg 8.0.3 This behaviour seems odd to me: CREATE TABLE mytable ( inta INTEGER ); CREATE OR REPLACE FUNCTION myfunction (inta integer) RETURNS integer AS $body$ begin insert into mytable(inta) values (inta); return(0); end; $body$ LANGUAGE 'plpgsql'; select myfunction(123); ERROR: synta

Re: [SQL] two sums in one query

2005-07-13 Thread Ramakrishnan Muralidharan
I have assuemed that the row will having eighter Debit account or Credit account, the following Query will give sum of debit and credit accounts SELECT SUM( CASE WHEN COALESCE( DEBIT , 0 ) <> 0 THEN COALESCE( AMOUNT , 0 ) ELSE 0 END ) AS DEBIT_AMT , SUM( CASE WHEN COALE

Re: [SQL] getting back autonumber just inserted

2005-07-13 Thread Larry Meadors
If you have a trigger on your table that inserts a record in a table and shares the same sequence, what value do you get back, the triggered curval, or the currently inserted one? Being a lazy bum, this is why I still prefer the "get key - insert record" approach. Less brain power required. ;-) L

Re: [SQL] getting back autonumber just inserted

2005-07-13 Thread Larry Meadors
Sounds like M$ SuckQL's @@identity value. ;-) Larry On 7/7/05, Michael Fuhr <[EMAIL PROTECTED]> wrote: > On Fri, Jul 08, 2005 at 01:56:26AM +0200, PFC wrote: > > >Do you mean with lastval()? Here's what happens: > > > > Hm, interesting, you mean the return value of lastval() also depends > > if

[SQL] Possible to use a table to tell what table to select from?

2005-07-13 Thread Frank Hagstrom
Hello I've been thinking on a potential problem I might get in a distant future, but once I started thinking on it I just as well had to check... Is it possible to have say ~ 6 tables, where the first one is a 'reference' to all the others (they all are with the same structure). The other 5 or so

[SQL] ORDER records based on parameters in IN clause

2005-07-13 Thread Riya Verghese
Thanks! This worked beautifully.   Here’s what I have: SELECT a.listing_ id FROM cls.listings  a JOIN (SELECT listing_id,count(listing_id) AS count FROM cls.tagslistings  WHERE    cust_id =27 AND tag_id IN (SELECT tag_id FROM cls.tags WHERE tag_name IN ('toys','263')) GROUP BY lis

[SQL] Dynamic Offset Determination

2005-07-13 Thread David Blankley
Problem Statement: I want to return n rows from a table. These n rows are relative to an offset. The part I can't figure out: The offset needs to be determined from values in the rows. Example: Given a table foo: CriteriaCol integer OrderedCol integer I can figure out the number of rows

Re: [SQL] Dynamic Offset Determination

2005-07-13 Thread David Blankley
I came up with a clever solution to this myself... I know the determined value for my CriteriaCol, so I can simply get the count of all the rows with criteria <= my value... SELECT count(*) FROM foo WHERE CriteriaCol<=constraint ORDER BY OrderCol; Thanks, Dave --

[SQL] Sql Query help: Remove Sub Selects

2005-07-13 Thread Rob
Hi Gang, I'm trying to optimize a query: This query below returns something like this: event_id | eu_tid | event_name | event_when | day | mon | start | end|event_users | contact_phone| contact_pager | num_opps --++-

Re: [SQL] getting back autonumber just inserted

2005-07-13 Thread Vivek Khera
On Jul 7, 2005, at 4:14 PM, Theodore Petrosky wrote: you have to use currval inside a transaction... begin; insert something that increments the counter; select currval('sequence_name'); end; using currval inside a transaction guarantees that the value is correct for your insert statement an

Re: [SQL] Generating a range of integers in a query

2005-07-13 Thread Scott Marlowe
On Wed, 2005-07-13 at 04:13, Aaron Bingham wrote: > Hello, > > I've got an interesting problem: I need to select all possible values > of an attribute that do /not/ occur in the database. > > This would be easy (in my case at least) if there were a way to > generate a table containing all integer

Re: [SQL] Generating a range of integers in a query

2005-07-13 Thread Jim Buttafuoco
I use the following function which returns a date series. You can modify it to return an int series instead create or replace function alldates(date,date) returns setof date as ' declare s alias for $1; e alias for $2; d date; begin d := s; while d <= e

Re: [SQL] Copy user privileges

2005-07-13 Thread Graham Vickrage
Thanks for the suggestions but as you guessed I do need to keep the old user and also groups would be unsuitable as I don't want either user to be able to see data on the other database. Thought there would be some SQL statement I could run on the sys tables but I don't know enough about the inter

Re: [SQL] Generating a range of integers in a query

2005-07-13 Thread Michael Glaesemann
On Jul 13, 2005, at 6:13 PM, Aaron Bingham wrote: This would be easy (in my case at least) if there were a way to generate a table containing all integers between 1 and n, where n is the result of a subquery. In my case, n will be at most a few hundred. I would like to be able to generate thi

[SQL] Generating a range of integers in a query

2005-07-13 Thread Aaron Bingham
Hello, I've got an interesting problem: I need to select all possible values of an attribute that do /not/ occur in the database. This would be easy (in my case at least) if there were a way to generate a table containing all integers between 1 and n, where n is the result of a subquery. In my c