pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: silly sad <sad@bankir.ru>
To: Ignacio Balcarce <ignacio.balcarce@vivatia.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: MSSQL to PostgreSQL - Issue trying to generate unique ID using actual date
Date: Thu, 18 Mar 2010 13:33:40 +0300
Message-ID: <4BA20184.3080000@bankir.ru> (raw)
In-Reply-To: <000001cac5e1$8851dbe0$98f593a0$@balcarce@vivatia.com>
References: <000001cac5e1$8851dbe0$98f593a0$@balcarce@vivatia.com>

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) + 1)) AS VARCHAR)
>
> + CAST(ISNULL(CAST(SUBSTRING(MAX(SEQ_ID),9,8) AS INTEGER),0) + 1 AS
>
> VARCHAR)
>
> FROM THUBAN_SEQ
>
> WHERE SUBSTRING(SEQ_ID,1,8)=
>
> REPLACE(SUBSTRING(CONVERT(CHAR(10),GETDATE(),20 ),1,10),'-','')
>
> )
>
> INSERT INTO THUBAN_SEQ VALUES (@NEWID)
>
> SELECT @NEWID AS ITEM_ID;
>
> GO
>

At a first glance
it looks like an

INSERT INTO thuban_seq(seq_id)
  VALUES (your_strange_string_processing( now() ))
   RETURNING seq_id;

But i couldn't interpret your extremely strange string processing with 
dates.
Please, FIRST OF ALL, get rid of this unnecessary brainfuck,
use postgres date-time arithmetic and clarify the idea of this routine.




view thread (7+ messages)  latest in thread

Message-ID: <4BA20184.3080000@bankir.ru>
Permalink:  ../4BA20184.3080000@bankir.ru/
Also on:    postgresql.org/message-id/4BA20184.3080000@bankir.ru

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sad@bankir.ru, ignacio.balcarce@vivatia.com
  Subject: Re: MSSQL to PostgreSQL - Issue trying to generate unique ID using actual date
  In-Reply-To: <4BA20184.3080000@bankir.ru>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox