RE: DB porting questions...
От | Michael Ansley |
---|---|
Тема | RE: DB porting questions... |
Дата | |
Msg-id | 7F124BC48D56D411812500D0B747251480F522@fileserver002.intecsystems.co.uk обсуждение исходный текст |
Ответ на | DB porting questions... ("Diehl, Jeffrey" <jdiehl@sandia.gov>) |
Список | pgsql-sql |
<p><font size="2">Hi, Jeff,</font><br /><font size="2"> </font><p><font size="2">>> 1)</font><br /><font size="2">>> I have a table:</font><br /><font size="2">>> create table a (</font><br /><font size="2">>> t timestamp not null,</font><br /><font size="2">>> ...</font><br/><font size="2">>> );</font><br /><font size="2">>> </font><br /><font size="2">>> I'm thinking that I can define a.t as not null default=now(). But >> will</font><br /><font size="2">>> this</font><br /><font size="2">>> work? That is, will it update a.t when I modified a given record?</font><br/><font size="2">You need to set the default, but you have to use now() in (single) quotes, otherwise allrecords will use the time that the CREATE statement was executed:</font><p><font size="2">t timestamp not null default'now()',</font><br /><font size="2">...or something close. It's in the docs somewhere too.</font><p><font size="2">>> 2)</font><br /><font size="2">>> I have another table:</font><br /><font size="2">>> create table b (</font><br /><font size="2">>> id int not null AUTO_INCREMENT,</font><br /><fontsize="2">>> ... </font><br /><font size="2">>> );</font><br /><font size="2">>> </font><br /><font size="2">>> To reproduce this behavior, I believe I need to use a sequence. The</font><br /><font size="2">>> problem</font><br /><font size="2">>> is that I have a lot of datato import into this table. How do I </font><br /><font size="2">>> import the old data without colliding withthe new sequence numbers?</font><br /><font size="2">What you do is create the id column of type SERIAL, then importyour data, and then immediately afterwards, use setval() to update the current value of the sequence to one more thanthe highest value that you imported. The syntax for setval() is in the docs. During the import of your data, the sequencewill not be used for incrementing the id, as it's only used as the default, not if you actually provide a value.</font><p><fontsize="2">Cheers...</font><br /><p><font size="2">MikeA</font><br /><code><font size="3"><br /><br />_________________________________________________________________________<br /> This e-mail and any attachments are confidentialand may also be privileged and/or copyright <br /> material of Intec Telecom Systems PLC (or its affiliated companies).If you are not an <br /> intended or authorised recipient of this e-mail or have received it in error, pleasedelete <br /> it immediately and notify the sender by e-mail. In such a case, reading, reproducing, <br /> printingor further dissemination of this e-mail is strictly prohibited and may be unlawful. <br /> Intec Telecom SystemsPLC. does not represent or warrant that an attachment hereto is free <br /> from computer viruses or other defects.The opinions expressed in this e-mail and any <br /> attachments may be those of the author and are not necessarilythose of Intec Telecom <br /> Systems PLC. <br /><br /> This footnote also confirms that this email message hasbeen swept by<br /> MIMEsweeper for the presence of computer viruses. <br /> __________________________________________________________________________<br/></font></code>
В списке pgsql-sql по дате отправления: