Re: [SQL] Emacs sql-postgres (please, sorry for question not about PostgreSQL).

2010-03-18 Thread Pavel Stehule
2010/3/18 Tom Lane : > Dmitriy Igrishin writes: >> I am using Emacs recently. I love sql-mode, to use with PostgreSQL, >> but I have problems with it. >> When my SQL file (or buffer) are small (50-100 lines) I can send >> it to SQLi buffer without any problems. But when I working with >> large SQL

Re: [SQL] Emacs sql-postgres (please, sorry for question not about PostgreSQL).

2010-03-18 Thread Pavel Stehule
Hello try to look on http://www.postgres.cz/index.php/PostgreSQL_SQL_Tricks#Terminal.27s_configuration Regards Pavel Stehule 2010/3/18 Dmitriy Igrishin : > Hello all Emacs users! > > I am using Emacs recently. I love sql-mode, to use with PostgreSQL, > but I have problems with it. > When my SQL

Re: [SQL] Emacs sql-postgres (please, sorry for question not about PostgreSQL).

2010-03-18 Thread Tom Lane
Dmitriy Igrishin writes: > I am using Emacs recently. I love sql-mode, to use with PostgreSQL, > but I have problems with it. > When my SQL file (or buffer) are small (50-100 lines) I can send > it to SQLi buffer without any problems. But when I working with > large SQL file (e.g. complex database

[SQL] Emacs sql-postgres (please, sorry for question not about PostgreSQL).

2010-03-18 Thread Dmitriy Igrishin
Hello all Emacs users! I am using Emacs recently. I love sql-mode, to use with PostgreSQL, but I have problems with it. When my SQL file (or buffer) are small (50-100 lines) I can send it to SQLi buffer without any problems. But when I working with large SQL file (e.g. complex database model, thou

Re: [SQL] MSSQL to PostgreSQL - Issue trying to generate unique ID using actual date

2010-03-18 Thread Ignacio Balcarce
Justin, Thanks in advance for your email. I forgot to tell than everyday IDs must start from 0. So… sequence id would look like: MMDD 0001, MMDD 0002, etc. Is there any way to make this sequence start from 0 every day? Thanks & Regards, Ignacio De: Justin Graf

Re: [SQL] MSSQL to PostgreSQL - Issue trying to generate unique ID using actual date

2010-03-18 Thread Justin Graf
OOPS did not mean to click send On 3/18/2010 12:53 PM, Ignacio Balcarce wrote: > > Justin, > > Thanks in advance for your email. I forgot to tell than everyday IDs > must start from 0. So… sequence id would look like: MMDD 0001, > MMDD 0002, etc. > > Is there any way to make this

Re: [SQL] MSSQL to PostgreSQL - Issue trying to generate unique ID using actual date

2010-03-18 Thread Justin Graf
On 3/18/2010 12:53 PM, Ignacio Balcarce wrote: > > Justin, > > Thanks in advance for your email. I forgot to tell than everyday IDs > must start from 0. So… sequence id would look like: MMDD 0001, > MMDD 0002, etc. > > Is there any way to make this sequence start from 0 every day?

Re: [SQL] MSSQL to PostgreSQL - Issue trying to generate unique ID using actual date

2010-03-18 Thread Justin Graf
On 3/17/2010 9:52 AM, Ignacio Balcarce wrote: > > Hi all, > > I am facing a problem trying to convert from MSSQL procedure to > PostgreSQL function. > > CREATE PROCEDURE dbo.THUBAN_SP_GENERATEID > > @NEWID VARCHAR(20) OUTPUT > > AS > > SET @NEWID = ( > > SELECT REPLACE(SUBSTRING(CONVERT(C

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 b

Re: [SQL] Simple aggregate query brain fart

2010-03-18 Thread Tom Lane
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

Re: [SQL] Simple aggregate query brain fart

2010-03-18 Thread Plugge, Joe R.
Mark, Change your query to this: SELECT id, count(*) FROM mytable GROUP BY id HAVING count(*) > 2; -Original Message- From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On Behalf Of Mark Fenbers Sent: Thursday, March 18, 2010 10:07 AM To: pgsql-sql@postgresql

[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

Re: [SQL] MSSQL to PostgreSQL - Issue trying to generate unique ID using actual date

2010-03-18 Thread silly sad
On 03/17/10 17:52, Ignacio Balcarce wrote: -- IF EXISTS A ROW IN THE TABLE STARTING WITH THE CURRENT_DATE Sorry, your field is not an atom => your database does not met a FIRST normal form. it needs normalization urgently. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To mak

Re: [SQL] MSSQL to PostgreSQL - Issue trying to generate unique ID using actual date

2010-03-18 Thread silly sad
On 03/17/10 17:52, Ignacio Balcarce wrote: CREATE PROCEDURE dbo.THUBAN_SP_GENERATEID @NEWID VARCHAR(20) OUTPUT AS SET @NEWID = ( SELECT REPLACE(SUBSTRING(CONVERT(CHAR(10),GETDATE(),20 ),1,10),'-','') + CAST(REPLICATE(0,8-LEN (ISNULL(CAST(SUBSTRING(MAX(SEQ_ID),9,8) AS INTEGER),0) +