X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 0B4FA564E0 for ; Tue, 15 Mar 2005 17:37:57 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 15562-02 for ; Tue, 15 Mar 2005 17:37:52 +0000 (GMT) Received: from www.lodestonetechnologies.com (lodestonetechnologies.com [69.64.33.50]) by svr1.postgresql.org (Postfix) with ESMTP id 363F3568CC for ; Tue, 15 Mar 2005 17:37:50 +0000 (GMT) Received: (qmail 15031 invoked from network); 15 Mar 2005 18:33:09 -0000 Received: from softdnserror (HELO ?192.168.253.3?) (68.69.152.123) by softdnserror with SMTP; 15 Mar 2005 18:33:09 -0000 Mime-Version: 1.0 (Apple Message framework v619.2) In-Reply-To: <011901c5297a$39334f20$0b00a8c0@forge> References: <4236FEF1.7050606@minas.demon.nl> <011901c5297a$39334f20$0b00a8c0@forge> Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <7c3af9cfcb7efac34c8d997d7ce19e9f@lodestonetechnologies.com> Content-Transfer-Encoding: 7bit From: Robert Perry Subject: Re: How to format a date with a serial number for DEFAULT? Date: Tue, 15 Mar 2005 12:30:21 -0500 To: pgsql-admin@postgresql.org X-Mailer: Apple Mail (2.619.2) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200503/230 X-Sequence-Number: 16728 I am far to lazy to bother actually trying it, but I believe prefixing your format string for the bigint returned by nextval with 'FM' will eliminate your need for the trim. On Mar 15, 2005, at 11:15 AM, Andrei Bintintan wrote: > CREATE TABLE test( > counter SERIAL, > foobar CHAR(18) > DEFAULT to_char(CURRENT_DATE, 'DDMMYYYY') || > trim(to_char(nextval('test_counter_seq'),'0000000000')), > tekst TEXT); > > I don't know exactly why the white space is in, but the trim function > takes > it out. > > Best regards, > Andy. > > ----- Original Message ----- From: "Michiel Lange" > > To: > Sent: Tuesday, March 15, 2005 5:27 PM > Subject: [ADMIN] How to format a date with a serial number for DEFAULT? > > >> Hello list, >> >> I am trying to create a table that hould countain a number formatted >> this >> way: YYYYMMDD########## >> >> Where the hashes should be padded to '0'. >> >> I have tried the following >> template_test=# CREATE TEMP TABLE test ( >> template_test(# counter SERIAL, >> template_test(# foobar CHAR(18) >> template_test(# DEFAULT CAST(date_part('year',current_date) AS TEXT) >> template_test(# || >> CAST(CAST(to_char(date_part('month',current_date),'00') AS INT) AS >> TEXT) >> template_test(# || >> CAST(CAST(to_char(date_part('day',current_date),'00') AS INT) AS TEXT) >> template_test(# || >> CAST(CAST(to_char(nextval('test_counter_seq'),'0000000000') AS INT) AS >> TEXT), >> template_test(# tekst TEXT); >> >> This resulted in something almost good, but I lost the padding zeroes. >> I got "20053151" >> >> Without the many CAST's like this: >> template_test=# CREATE TEMP TABLE test ( >> template_test(# counter SERIAL, >> template_test(# foobar CHAR(18) >> template_test(# DEFAULT CAST(date_part('year',current_date) AS TEXT) >> template_test(# || >> to_char(date_part('month',current_date),'00') >> template_test(# || to_char(date_part('day',current_date),'00') >> template_test(# || >> to_char(nextval('test_counter_seq'),'0000000000'), >> template_test(# tekst TEXT); >> >> Resulted in something almost right as well, but now to_char adds a >> space >> before each to_char >> I would get a result like "2005 03 05 0000000001" >> >> What options do I have to get this straight? >> >> Mind that I created TEMP tables to test how I should set my default >> value.... >> TIA >> Michiel >> >> ---------------------------(end of >> broadcast)--------------------------- >> TIP 4: Don't 'kill -9' the postmaster >> >> > > > > ---------------------------(end of > broadcast)--------------------------- > TIP 9: the planner will ignore your desire to choose an index scan if > your > joining column's datatypes do not match >