[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH 2/2] Modify upgrade_bibtex.sql: Create a function bibentry and pass a parameter to bibtex()



From: Akshita Jha <akshita-guest@users.alioth.debian.org>

---
 sql/upgrade_bibtex.sql | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/sql/upgrade_bibtex.sql b/sql/upgrade_bibtex.sql
index dfb30ac..ea9ebf8 100644
--- a/sql/upgrade_bibtex.sql
+++ b/sql/upgrade_bibtex.sql
@@ -1,8 +1,24 @@
 /************************************************************************************
+ * Get the table from which references are to be taken                             *
+ ************************************************************************************/
+
+CREATE OR REPLACE FUNCTION bibentry (bibref text, sources text DEFAULT NULL)
+RETURNS TABLE(source text, rank text, package text) LANGUAGE SQL
+AS $$
+  IF sources IS NULL THEN
+  BEGIN
+    SELECT DISTINCT source, rank, package FROM bibref p;
+  ELSE
+    SELECT DISTINCT source, rank, package FROM bibref p INNER JOIN sources s ON s.source = p.source;
+  END IF;
+$$;
+
+
+/************************************************************************************
  * Create a BibTex file from references taken from bibref table only.               *
  ************************************************************************************/
 
-CREATE OR REPLACE FUNCTION bibtex ()
+CREATE OR REPLACE FUNCTION bibtex (bibtable text)
 RETURNS SETOF TEXT LANGUAGE SQL
 AS $$
   SELECT DISTINCT
@@ -61,7 +77,7 @@ AS $$
             AS bibentry
 --         p.source         AS source,
 --         p.rank           AS rank,
-    FROM (SELECT DISTINCT source, package, rank FROM bibref) p
+    FROM (SELECT DISTINCT source, package, rank FROM bibtable) p
     LEFT OUTER JOIN bibref bibkey     ON p.source = bibkey.source     AND bibkey.rank     = p.rank AND bibkey.package     = p.package AND bibkey.key     = 'bibtex'
     LEFT OUTER JOIN bibref bibyear    ON p.source = bibyear.source    AND bibyear.rank    = p.rank AND bibyear.package    = p.package AND bibyear.key    = 'year'  
     LEFT OUTER JOIN bibref bibmonth   ON p.source = bibmonth.source   AND bibmonth.rank   = p.rank AND bibmonth.package   = p.package AND bibmonth.key   = 'month'  
-- 
1.9.1


Reply to: