Using timestamp values correctly : timestamp « Date Timezone « PostgreSQL

PostgreSQL
1. Aggregate Functions
2. Analytical Functions
3. Array
4. Constraints
5. Cursor
6. Data Type
7. Database
8. Date Timezone
9. Index
10. Inheritance
11. Insert Delete Update
12. Math Functions
13. Postgre SQL
14. Select Query
15. Sequence
16. Store Procedure Function
17. String Functions
18. Subquery
19. Table
20. Table Joins
21. Transaction
22. User Previliege
23. View
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
PostgreSQL » Date Timezone » timestamp 
Using timestamp values correctly


postgres=#
postgres=# CREATE TABLE "shipments" (
postgres(#      "id" integer DEFAULT nextval('"shipments_ship_id_seq"'::text) NOT NULL,
postgres(#      "customer_id" integer,
postgres(#      "isbn" text,
postgres(#      "ship_date" timestamp with time zone
postgres(# );
CREATE TABLE
postgres=#
postgres=# insert into shipments values (375,  142,  '039480001X','2004-01-06 09:19:21-01');
INSERT 0 1
postgres=# insert into shipments values (323,  671,  '0451160916','2004-02-14 10:26:41-02');
INSERT 0 1
postgres=# insert into shipments values (998,  1045, '0590445065','2004-03-12 12:39:47-03');
INSERT 0 1
postgres=#
postgres=#
postgres=# -- Using timestamp values correctly
postgres=#
postgres=# CREATE FUNCTION add_shipment (integer, text) RETURNS timestamp AS '
postgres'#   DECLARE
postgres'#      -- Declare aliases for function arguments.
postgres'#     customer_id ALIAS FOR $1;
postgres'#     isbn ALIAS FOR $2;
postgres'#
postgres'#     shipment_id INTEGER;
postgres'#     right_now timestamp;
postgres'#
postgres'#   BEGIN
postgres'#     right_now := ''now'';
postgres'#
postgres'#     SELECT INTO shipment_id id FROM shipments ORDER BY id DESC;
postgres'#
postgres'#     shipment_id := shipment_id + 1;
postgres'#
postgres'#     INSERT INTO shipments VALUES ( shipment_id, customer_id, isbn, right_now );
postgres'#
postgres'#     RETURN right_now;
postgres'#   END;
postgres'# ' LANGUAGE 'plpgsql';
CREATE FUNCTION
postgres=#
postgres=# select add_shipment(1, '123');
      add_shipment
-------------------------
 2006-10-18 19:15:49.125
(1 row)

postgres=#
postgres=# select * from shipments;
 id  | customer_id |    isbn    |         ship_date
-----+-------------+------------+----------------------------
 375 |         142 | 039480001X | 2004-01-06 02:19:21-08
 323 |         671 | 0451160916 | 2004-02-14 04:26:41-08
 998 |        1045 | 0590445065 | 2004-03-12 07:39:47-08
 999 |           1 | 123        | 2006-10-18 19:15:49.125-07
(4 rows)

postgres=#
postgres=# drop FUNCTION add_shipment (integer, text);
DROP FUNCTION
postgres=# drop table shipments;
DROP TABLE
postgres=#
postgres=#
           
       
Related examples in the same category
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.