मैं एक 'तारीख' प्रकार है कि मौजूदा महीने के पहले दिन से मेल खाती है पाने के लिए कोशिश कर रहा हूँ में महीने के पहले तिथि प्राप्त करें। मूल रूप से मेरी तालिकाओं में से एक एक तारीख को संग्रहीत करता है, लेकिन मैं इसे हमेशा महीने के पहले होना चाहते हैं, तो मैं एक ट्रिगर है कि अब मिल जाएगा() और फिर एक 1.postgres
Q
postgres
26
A
उत्तर
57
के साथ दिन की जगह बनाने के लिए कोशिश कर रहा हूँ आप अभिव्यक्ति date_trunc('month', current_date)
उपयोग कर सकते हैं। एक का चयन करें बयान के साथ प्रदर्शन किया। । ।
select date_trunc('month', current_date)
2013-08-01 00:00:00-04
समय निकालने के लिए, तिथि पर कास्ट करें।
select cast(date_trunc('month', current_date) as date)
2013-08-01
आप यकीन है कि आपने उस स्तंभ हमेशा दुकान केवल एक महीने के पहले, आप भी एक चेक बाधा का उपयोग करना चाहिए करना चाहिए।
create table foo (
first_of_month date not null
check (extract (day from first_of_month) = 1)
);
insert into foo (first_of_month) values ('2015-01-01'); --Succeeds
insert into foo (first_of_month) values ('2015-01-02'); --Fails
ERROR: new row for relation "foo" violates check constraint "foo_first_of_month_check" DETAIL: Failing row contains (2015-01-02).
17
date_trunc()
यह करना होगा।
SELECT date_trunc('MONTH',now())::DATE;
http://www.postgresql.org/docs/current/static/functions-datetime.html
2
चयन TO_DATE ('2017/12/12', 'YYYY-MM-01');
2017-12-01
संबंधित मुद्दे
- 1. Postgres
- 2. Postgres
- 3. postgres
- 4. Postgres
- 5. Postgres
- 6. Postgres
- 7. कैसे Postgres
- 8. Heroku postgres
- 9. कैसे postgres
- 10. psql postgres
- 11. pode/postgres
- 12. "नाम" postgres
- 13. Postgres फ़ाइलों
- 14. postgres कनेक्शन की समस्या
- 15. Postgres: टाइमस्टैम्प बड़ा अब
- 16. ऑपरेटर ~ <~ Postgres
- 17. डोकर postgres निर्दिष्ट पोर्ट
- 18. Postgres FK समग्र पी
- 19. Postgres तारीख अतिव्यापी बाधा
- 20. Postgres रेल आदेश
- 21. उपयोग परिणाम (postgres 8.3)
- 22. postgres पाठ में
- 23. प्रतिलिपि से और Postgres
- 24. उपयोगकर्ता 'postgres' त्रुटि
- 25. Convert तारीख postgres
- 26. Postgres नियम CTE प्रश्नों
- 27. Node.js और postgres LISTEN
- 28. su postgres: क्षमा करें?
- 29. उपयोगकर्ता प्रमाणीकरण उपयोगकर्ता "postgres"
- 30. Postgres गणित अभिव्यक्ति तालिका
इस जवाब के साथ क्या समस्या है? – Victorqedu
शायद सिर्फ इतना है कि आप बल्कि CURRENT_DATE की तुलना में एक स्थिर डेटा का इस्तेमाल किया()? –