By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,781 Members | 1,284 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,781 IT Pros & Developers. It's quick & easy.

Default Value in Table Setup Help

P: n/a
Dev
Hello all,

I am working on setting up a table that will append a sequence to the end
of the value inserted.
Example;
INSERT INTO test (test) VALUES ('abcd');
And have the data in the database be;
abcd0001

Now I do have things setup else where were the default value for the field
is such:
default ('abcd'::text || lpad(text(nextval('test_sequence'::text)), 4,
'0'::text))

But i want the "abcd" or what erver to be added in the insert?

What am I missing to make this happen?

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
At 02:57 PM 8/18/03 -0400, Dev wrote:
Hello all,

I am working on setting up a table that will append a sequence to the end
of the value inserted.
Example;
INSERT INTO test (test) VALUES ('abcd');
And have the data in the database be;
abcd0001

Now I do have things setup else where were the default value for the field
is such:
default ('abcd'::text || lpad(text(nextval('test_sequence'::text)), 4,
'0'::text))

But i want the "abcd" or what erver to be added in the insert?

What am I missing to make this happen?


I don't think you can do what you want to do with a column
default. Instead you want to look at the rewrite rules. You can find
information about them here:

http://www.postgresql.org/docs/7.3/i...reaterule.html

If I'm wrong I'm sure someone here will correct me :).

--- Adam Kavan
--- ak****@cox.net
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 11 '05 #2

P: n/a
On Mon, 18 Aug 2003, Dev wrote:
Hello all,

I am working on setting up a table that will append a sequence to the end
of the value inserted.
Example;
INSERT INTO test (test) VALUES ('abcd');
And have the data in the database be;
abcd0001

Now I do have things setup else where were the default value for the field
is such:
default ('abcd'::text || lpad(text(nextval('test_sequence'::text)), 4,
'0'::text))

But i want the "abcd" or what erver to be added in the insert?

What am I missing to make this happen?


You don't want to use a default (since that'll be ignored if you actually
pass in a value for the column). You probably want a before trigger that
alters the value that was inserted before the insertion actually happens.
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 11 '05 #3

P: n/a
On Mon, Aug 18, 2003 at 14:57:12 -0400,
Dev <de*@umpa-us.com> wrote:
Hello all,

I am working on setting up a table that will append a sequence to the end
of the value inserted.
Example;
INSERT INTO test (test) VALUES ('abcd');
And have the data in the database be;
abcd0001

Now I do have things setup else where were the default value for the field
is such:
default ('abcd'::text || lpad(text(nextval('test_sequence'::text)), 4,
'0'::text))

But i want the "abcd" or what erver to be added in the insert?

What am I missing to make this happen?


I think you want to use a trigger to do this. The default function only
gets used if you don't supply a value.

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 11 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.