{"id":504,"date":"2013-08-19T11:52:05","date_gmt":"2013-08-19T11:52:05","guid":{"rendered":"http:\/\/vickistan.com\/?p=504"},"modified":"2024-05-03T14:01:24","modified_gmt":"2024-05-03T14:01:24","slug":"postgres-examples","status":"publish","type":"post","link":"https:\/\/vickistan.com\/?p=504","title":{"rendered":"PostgreSQL examples"},"content":{"rendered":"<p>http:\/\/darthdeus.github.io\/blog\/2013\/08\/19\/postgresql-basics-by-example\/<\/p>\n\n\n<p>To look at a stored procedure:<br \/><br \/>Use this to find the procedure name:<br \/><br \/><code>SELECT routine_schema As schema_name, routine_name As procedure_name FROM information_schema.routines;<\/code><br \/><br \/>Then use this from the psql prompt to read the sql:<br \/><br \/><code>SELECT pg_get_functiondef(( SELECT oid FROM pg_proc WHERE proname = '&lt;function_name>')); <br \/><\/code><br \/>To create a table with an auto-incrementing index:<br \/><br \/><code>database=# CREATE TABLE VLS_TEST( <br \/>id INTEGER DEFAULT nextval('jobs_tags_id_seq'::regclass) NOT NULL,<br \/>job_id integer NOT NULL, <br \/>TEST TEXT NOT NULL); <br \/><br \/><\/code>To insert a row into this table, just don&#8217;t include the id field:<code><br \/><br \/>database=# INSERT INTO VLS_TEST (job_id, TEST) VALUES ( 234, 'This is test text.'); <br \/>INSERT 0 1 <br \/><br \/>database=# SELECT * from VLS_TEST; <br \/>  id | job_id | test <\/code><br \/><code>------+--------+-------------------- <\/code><br \/><code>8223 | 234 | This is test text. <\/code><br \/><code>(1 row)<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/darthdeus.github.io\/blog\/2013\/08\/19\/postgresql-basics-by-example\/ To look at a stored procedure: Use this to find the procedure name: SELECT routine_schema As schema_name, routine_name As procedure_name FROM information_schema.routines; Then use this from the psql prompt to read the sql: SELECT pg_get_functiondef(( SELECT oid FROM pg_proc &hellip; <a href=\"https:\/\/vickistan.com\/?p=504\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-504","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts\/504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=504"}],"version-history":[{"count":4,"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts\/504\/revisions"}],"predecessor-version":[{"id":815,"href":"https:\/\/vickistan.com\/index.php?rest_route=\/wp\/v2\/posts\/504\/revisions\/815"}],"wp:attachment":[{"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vickistan.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}