3r33333. 3r3-31. I hasten to share the good news: the life of the authors of articles on PostgreSQL and their readers has become a little better. 3r33333. 3r33333. 3r33333. 3r33333. As all habropolisters know, a special 3r-3261 tag is used to format the source code. which highlights the syntax. It is also no secret that the backlighting does not always turn out to be ideal, and then the authors (who cares how their articles look) are forced to engage in amateur performances — color their code with the help of 3r-3261. . 3r33333. 3r33333. 3r33333. 3r33333. Everything was especially sad with PostgreSQL, since the backlight covered more or less standard SQL and categorically did not understand the specifics of our DBMS. As time went by, Alexey boomburum diligently fixed my fonts on the source (and I back) until it became obvious that the backlight had to be repaired. Finally Daler daleraliyorov prompted the exit: add PostgreSQL support to the library. highlight which Habr uses. And now - ready, welcome. 3r33333. 3r33333. 3r3305. 3r33333. 3r33333.
pgsql: SQL, PL /pgSQL and all
3r33333. 3r33333. So, the secret of the right lighting - in the new language 3r33214. pgsql . You can select it in the menu (“source code” button) or specify it manually. In html for this you need to write 3r33333. 3r33333. 3r33333. 3r33333. 3r33333. my code is 3r33333. 3r33333. 3r33333. 3r33333. 3r33333. 3r33333. and in markdown - like this: 3r33333. 3r33333. 3r33333. `` `pgsql 3r33333. my code is 3r33333. 3r33333. `` ` 3r33333. 3r33333. 3r33333. In principle, highlightjs can determine the language itself, but normally it works only for large code fragments; on small pieces, autodetection often misses. In addition, autodetection takes time, so if you specify the language explicitly, the code will quickly play with colors. 3r33333. 3r33333. 3r33333. 3r33333. For example, to get 3r33333. 3r33333. 3r33333.
CREATE TABLE aircrafts_data (3r33333. Aircraft_code character (3) NOT NULL, Model jsonb NOT NULL, Range integer NOT NULL, CONSTRAINT aircrafts_range_check CHECK ((range> 0)) 333333333333333 3r33333.
3r33333. 3r33333. we write 3r33333. 3r33333. 3r33333. 3r33333. 3r33333. CREATE TABLE aircrafts_data ( 3r33333. aircraft_code character (3) NOT NULL, 3r33333. model jsonb NOT NULL, 3r33333. range integer NOT NULL, 3r33333. CONSTRAINT aircrafts_range_check CHECK ((range> 0)) 3r33333. ); 3r33333. 3r33333. 3r33333. 3r33333. 3r33333. 3r33333. The same pgsql language also colors PL /pgSQL code. For example, to get 3r33333. 3r33333. 3r33333.
CREATE FUNCTION get_available_flightid (date) RETURNS SETOF integer AS $$ BEGIN RETURN QUERY SELECT flightid FROM flight WHERE flightdate> = $ 1 AND flightdate < ($1 + 1); IF NOT FOUND THEN RAISE EXCEPTION 'There are no flights to date:%.', $ 1; 3r33333. END IF; 3r33333. RETURN; 3r33333. END $$ LANGUAGE plpgsql; 3r33333.
3r33333. 3r33333. we write 3r33333. 3r33333. 3r33333. 3r33333. 3r33333. CREATE FUNCTION get_available_flightid (date) RETURNS SETOF integer AS $$ 3r33333. 3r33333. $$ LANGUAGE plpgsql; 3r33333. 3r33333. 3r33333. 3r33333. 3r33333. 3r33333. The subtlety is that the character strings are enclosed in dollars, 3r3303. Always 3r3306. highlighted as code, and the lines in the apostrophes are not highlighted 3r3303. never . I considered different options, but this one seemed to be the most adequate. 3r33333. 3r33333. 3r33333. 3r33333. The ability of highlightjs to automatically determine the language of a fragment allows highlighting functions in other languages. For example, everything will work for PL /Perl: 3r33333. 3r33333. 3r33333.
CREATE FUNCTION perl_max (integer, integer) RETURNS integer AS $$ my ($ x, $ y) = @_; 3r33333. if (not defined $ x) {3r3333318. return undef if not defined $ y; 3r33333. return $ y; 3r33333.} return $ x if not defined $ y; 3r33333. return $ x if $ x> $ y; 3r33333. return $ y; 3r33333. $$ LANGUAGE plperl; 3r33333.
3r33333. 3r33333. To do this, you do not need anything special, just write 3r33333. 3r33333. 3r33333. 3r33333. 3r33333. CREATE FUNCTION perl_max (integer, integer) RETURNS integer AS $$ 3r33333. 3r33333. $$ LANGUAGE plperl; 3r33333. 3r33333. 3r33333. 3r33333. 3r33333. 3r33333. Of course, the chosen language depends only on what is written inside the dollars, and is in no way determined by what is written after LANGUAGE. 3r33333. 3r33333. 3r33333. 3r33333. In general, the backlight corresponds to the recently released 11th version of PostgreSQL. 3r33333. 3r33333. 3r33333. 3r33333. There were many doubts about the highlighting of functions. Unfortunately, to distinguish the name of a function from, for example, the name of a table, a full-fledged syntactic analysis is needed, and this is not solved within the framework of syntax highlighting. You can make a long list of standard functions and color them, but what about the functions of the numerous extensions? As a result, I decided not to color at all - all the same, everything rests on the keywords, but the variegation diminished. 3r33333. 3r33333. 3r33333. 3r33333.
plaintext: text, just text
3r33333. 3r33333. Sometimes the article is required to issue the results of the query. Of course, there are no keywords there, you don't need to highlight anything, but I want the text to look “console”, just like code. For this, you can now use the special language plaintext . For example, to get 3r33333. 3r33333. 3r33333.
WITH xmldata (data) AS (VALUES ($$ 3r33232. 3r33318. 3r31818. $ Xxxx) 3r SELECT xmltable. * FROM XMLTABLE (XMLNAMESPACES ('http://example.com/myns' AS x, 'Http://example.com/b' AS "B"), '/X: example /x: item' PASSING (SELECT data FROM xmldata) COLUMNS foo int PATH '@foo', Bar int PATH '@B: bar'); 3r33333.
3r33333. 3r33333. we write 3r33333. 3r33333. 3r33333. 3r33333. 3r33333. WITH xmldata (data) AS (VALUES ($$ 3r33333. 3r33333. 3r33333. 3r33333. 3r33333. 3r33333. foo | bar 3r33333. ----- + ----- 3r33333. 1 | 2 3r33333. 3 | 4 3r33333. 4 | 5 3r33333. (3 rows) 3r33333. 3r33333. 3r33333. 3r33333. 3r33333. Plaintext should always be specified explicitly, it is not automatically detected. 3r33333. 3r33333. 3r33333. 3r33333. I hope that the innovation you enjoy and come in handy. If you find an error in how the code is highlighted (and errors are inevitable, too context-sensitive syntax in SQL), create a task for 3r39797. github project , and even better - offer a solution. 3r33333. 3r33333. 3r33333. 3r33333. 3r3303. P. S. Do not forget about the conference 3r3304. PGConf 3r3305. to be held February 4-6 in Moscow. Applications for reports are accepted until December 5! 3r3306. 3r33333. 3r33333. 3r33333. 3r33311. ! function (e) {function t (t, n) {if (! (n in e)) {for (var r, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e.parentNode.insertBefore (r, e)}; "[object Opera]" == e.opera? a.addEventListener? a.addEventListener ("DOMContentLoaded", d,! 1): e.attachEvent ("onload", d ): d ()}}} t ("//mediator.mail.ru/script/2820404/"""_mediator") () (); 3r33312. 3r33333. 3r33333. 3r33333. 3r33333. 3r33333.