[SQL] [Newbie] migrating a stored procedure from MSSQL to postgresql

2003-08-15 Thread Bengali
Hi, I am a postgresql and stored procedures beginner and I would like to know if the stored procedure I am trying to migrate to plpgsql from MSSQL is correct. Here 's the only table involved in the stored procedure: create table ManufacturerOrders ( OrderNumber serial, SKU int not null,

Re: [SQL] Optional join

2003-08-15 Thread David Fetter
"Slawek Jarosz" <[EMAIL PROTECTED]> wrote: > Hi, > I trying to write a query that will join 2 tables. Here's the > concept: > Table 1: table1, primary key pk1 > Table 2: table2, primary key pk2 > One of the fields (f2) in table2 contains either the primary key of > table1 or a NULL value. So

Re: [SQL] How to optimize this query ?

2003-08-15 Thread ProgHome
As I am using mysql 4.0 right now (we’ve got a stupid problem with the 4.1 with the authentification protocol we can’t figure out) and the last subquery (the one in the last LEFT JOIN) MUST be removed …   So I tried the following query:   SELECT    L.* FROM lead L LEFT JOIN purchase P

Re: [SQL] About primary keys -- made some progress

2003-08-15 Thread Tim Andersen
This might not be the cleanest solution, but it runs fast and it retrieved the information I need. I broke it down into pieces and created several views to query from to simplify it for myself. The first four statements are views and the last one is the query I was originally trying to get. (note

Re: [SQL] About primary keys.

2003-08-15 Thread Tim Andersen
I looked in the info.c on line 2891 of the psqlodbc-7.2.5 to find this SQL logic (courtesy of Tom Lane) select ta.attname, ia.attnum from pg_attribute ta, pg_attribute ia, pg_class c, pg_index i, pg_namespace n where c.oid = i.indrelid AND n.oid = c.relnamespace AND i.indisprimary = 't' AND ia

Re: [SQL] About primary keys.

2003-08-15 Thread Tom Lane
Tim Andersen <[EMAIL PROTECTED]> writes: > The query I have so far only gets columns that are > part of a primary key. >... >and pga1.attnum = i.indkey[pga2.attnum-1]; This is wrong because you are looking at only one indkey position, and the attribute could be in any position of t

Re: [SQL] About primary keys.

2003-08-15 Thread Tim Andersen
I'm new to PostgreSQL but I am familiar with DB2, Oracle and Sybase. I must say, I am impressed with PostgreSQL so far! In order to compare databases across DBMS platforms, we need to create a view that queries from the system catalog tables. This view returns all of the columns in the database

Re: [SQL] sequence

2003-08-15 Thread Tom Lane
"cristi" <[EMAIL PROTECTED]> writes: > What is wrong here? > insert into table_name (field_name) values (select > setval('sequence_name')-1) as currval); Either too few parentheses, or too many ;-) You could write this as an INSERT/SELECT: insert into table_name (field_name) select setval('seq

Re: [SQL] sequence

2003-08-15 Thread Bertrand Petit
On Fri, Aug 15, 2003 at 12:32:36PM +0300, cristi wrote: > What is wrong here? > > insert into table_name (field_name) values (select > setval('sequence_name')-1) as currval); This should be better: INSERT INTO table_name (field_name) VALUES (nextval('sequence_name')); -- %!PS 2

Re: [SQL] sequence

2003-08-15 Thread Dennis Björklund
On Fri, 15 Aug 2003, cristi wrote: > What is wrong here? > > insert into table_name (field_name) values (select > setval('sequence_name')-1) as currval); Your probably want this instead: insert into table_name (field_name) values (nextval('sequence_name')); The reason why your insert fail ab

[SQL] sequence

2003-08-15 Thread cristi
What is wrong here? insert into table_name (field_name) values (select setval('sequence_name')-1) as currval); ---(end of broadcast)--- TIP 4: Don't 'kill -9' the postmaster