5 ms·
> OK I have a table in postgresql and I am adding a trigger such that when an insert happens on that table, an insert happens on another table. The second table
by bun_at_work 3y ago
> OK I have a table in postgresql and I am adding a trigger such that when an insert happens on that table, an insert happens on another table. The second table has a constraint. What happens to the first insert if the second insert violates the constraint?
How can I get help with this now?
Google result 1: https://stackoverflow.com/questions/77148711/create-a-trigger-on-insert-that-creates-another-trigger-on-a-different-table-in https://stackoverflow.com/questions/77148711/create-a-trigge...
Google result 2: https://dba.stackexchange.com/questions/307448/postgresql-trigger-insert-on-another-table-after-update-and-update-other-tables https://dba.stackexchange.com/questions/307448/postgresql-tr...
Like 90% of my questions like this are going to ChatGPT these days.
I can figure it out via the docs, but ChatGPT is SO convenient for things like this.
- deleted 3y ago[deleted]
- netcraft 3y agoAgreed that chatgpt is great for this kind of thing - a coworker is working on this GPT specifically for postgres https://chat.openai.com/g/g-uXYoYQEFi-sql-sage https://chat.openai.com/g/g-uXYoYQEFi-sql-sage But with it being down, my biggest advice would be to try it and see. something like dbfiddle.uk is perfect for these kinds of tests.
- SoftTalker 3y ago> What happens to the first insert if the second insert violates the constraint? Try it and see? Why do you need an AI to help with this?
- speedgoose 3y agoWhy do you use an internet search engine when you can walk to the library?
- rurp 3y agoThe question at hand is pretty easy to test manually and the information you get is much more useful. You will get to see the exact behavior for yourself, can easily build on the test case as related questions come up, and you know the information you are getting is correct rather than a hallucination. Copying information from ChatGPT is the newer version of blindly copying answers from StackOverflow. It often works out ok and at times makes sense to do, but it can easily lead to software flaws and doesn't do much to build a better undersanding of the domain which is necessary to solve more difficult challenges that don't fit into a Q&A format well.
- speedgoose 3y agoIn my experience, I encounter more issues and waste more time when I fiddle on my own and try stuff compared to doing the same, but using chatGPT. There is a lot of knowledge that I don’t want to have expertise with. Sure, I could carefully read the PostgreSQL documentation about triggers and implement it myself, or I could get the job done in a few minutes and procrastinate on HN instead.
- JoshuaDavid 3y ago> The question at hand is pretty easy to test manually and the information you get is much more useful. This approach can be hazardous to the health of the product you're building. For example, if you take this approach to answer the question of "what happens if I have two connections to a MySQL database, start a transaction in one of them and insert a row (but don't commit) and then issue a SELECT which would show the inserted row", then you will see consistent results across all of the experiments you run with that particular database, but you could easily end up with bugs that only show up when the transaction isolation level changes from how you tested it. Whereas if you search for or ask that question, the answers you get will likely mention that transaction isolation levels are a thing. You might also be able to get this level of knowledge by reading the manual, though there will still be things that are not included in the manual but do come up regularly in discussions on the wider internet.
- 3y ago
- Tommstein 3y agoYou can also, uh, just try it with a trivial test and see what happens.
- swatcoder 3y agoWell, were it possible, I'd say go back in time and study your tools so that you're not spending the journeyman period of your career ricocheting between tutorials and faqs. Failing that, read the documentation. Failing that, stand up a quick experiment. Somehow, we survived before ChatGPT and even before saturated question boards. Those strategies are still available to you and well worth learning
- EnergyAmy 3y agoWe also survived before the internet and indoor plumbing and fire, and yet life is so much better now.
- dvfjsdhgfv 3y agoI see your point but the world changes so fast. Back in my day you just needed to learn C, understand algorithms and so on and then you could get deeper in an area or two. Today, you need to understand and be able to proficiently use so many technologies that you can feel lost. And this is what happens when, say, you loose a job you've been doing for 10-15 years. You need to re-learn the world. And a lifetime is not enough to do it the way we used to do it.
- deleted 3y ago[deleted]
- mritchie712 3y agoI'd go straight to the experiment, create the tables on a local postgresdb and try to get it to work.
- linsomniac 3y agoThe "good old days weren't always good". I'm tired of either limiting myself to the information I have on the top of my head, the LLMs are really helping allow me to be creative and stretch out to do things that are just beyond my bread and butter, or things that I do infrequently.
- 3y ago
- morsch 3y agoSo ChatGPT says -- to me, a minute ago, ymmv -- it will rollback the first insert. Now what? Do you believe it? Cool. I wouldn't. I would confirm its claim, either by Googling or by trying it myself. Also, when I asked it "what if I use PostgreSQL's non-transactional triggers", which I thought I just made up, it told me it wouldn't roll back the first insert: Non-transactional triggers are executed as part of the statement that triggered them, but they don't participate in the transaction control. So now I don't know what to think.